mercredi 23 mars 2016

Java Spring Model Attribute across multiple views

I have a web application created with java and spring (3.2.4). To send data to the client we use ModelMap

 @RequestMapping(value = "search.view", method = RequestMethod.GET)
 public String search(final HttpServletRequest request, final ModelMap map) { 
      ...
      map.addAttribute("searchSelectList", searchSelectList);
}

Because we need some information across multiple requests we use @SessionAttributes as well.

@Controller(value = "controller")
@SessionAttributes({ "searchSelectList" })
public class BriefingController extends AbstractBriefingController { .. }

Now we have some Memory problems on our server because we increased the Session lifetime massively.

So I'm looking for a possibility to store information over two requests. (So that i don't have to store them into the session)

Use case example:
I have a search where the user can search for a string. Now if he don't write precisely, i would like to show him a selection Table where he can select the correct search string.
The selected item is sent back to the server and the server sends back the search result. In this situation i loose the selection Table information. But i would like to still show this table after search result will be displayed.

@RequestMapping(value = "search.view", method = RequestMethod.GET)
public String search(final HttpServletRequest request, final ModelMap map) { 
      // load searchlist
      map.addAttribute("searchSelectList", searchSelectList);
}

@RequestMapping(value = "selectSearchItem.view", method = RequestMethod.GET)
public String selectSearchItem(final HttpServletRequest request,  @RequestParam("searchItemId") final String searchItemId, final ModelMap map) { 

      // here I would like to access the searchSelectList again!

}

I hope i wrote understandable. Otherwise just ask :)




Aucun commentaire:

Enregistrer un commentaire