Tiles Framework : refresh only body content

前端 未结 2 1215
渐次进展
渐次进展 2021-02-04 21:38

we have a Tiles layout page having Header, Menu, Body and Footer. In this layout whenever user does some action in the Menu lists, the whole Layout (Incl Header, menu and footer

2条回答
  •  失恋的感觉
    2021-02-04 22:09

    To do this you need to use ajax calls. The general procedure would be:

    1.- Create and define a tile which will be your base, composed with your header, body and footer, which will look like this:

    whatever goes here...
    whatever goes here....
    whatever goes here...

    let's consider each of those divs to be one tile in your definition:

    
        
    
             
    
    

    2.- Create and define all the different jsp which will replace your body content, please remember that this jsp must contain only the body elements. Let's say you have 2 other body contents ready to be shown in your page, each one will be a tile:

    whatever goes here again...
    whatever goes here again 2

    3.- At this point you have both the base jsp tile and 2 other jsp which contain the body content. Now we need a struts action which will act as a service, returning the corresponding body depending on the ajax request. Do this as a normal action, and at the mapping.findForward method in the end, return the jsp which contains your body. You can either create one action for each body content or a single DispatchAction which contains a method for each body.Second option is cleaner, and the action would be defined like this:

    
        
        
    
    

    4.- To switch content, use javascript or jquery to make an ajax call and load the returned jsp into your body. This is an example of the method which would switch the content in jQuery, using .load() as an ajax call:

    function switchContent(whichContent){
         $('#bodyTile').children().remove();
         $('#bodyTile').load("/pathToYourApp/bodySwitcher.do?method="+whichContent);
    }
    

    Don't get discouraged by how long the answer is, I'm just trying to explain cleanly. This is actually pretty easy to do, and question is more jquery/javascript related than anything else, the only detail is how to use a struts action as a service. Good luck.

提交回复
热议问题