My previous for the same problem , Now, I am in a same situation and looking for some solutions / suggestions.
My Restrictions are
- My Bean has to be request scoped
- I cannot use tomahawk - we use a customized app server built on tomcat + SOA - blah , blah so we cannot use.
I have a collection of search results which is different for each search criteria (and thats why the bean is request scoped - because the user would want to use diff tabs in the same browser to compare results or do whatsoever he wants ). I like to show the search results in pages like prev + next.
like this :
<tr>
<td colspan="14" class="WhiteRowSmallText">
<div align="right">
<h:commandLink rendered="#{adminBean.showPrev}" action="#{adminBean.goPrev}">
<h:outputText> < Prev  | </h:outputText>
</h:commandLink>
<h:outputText>  |  </h:outputText>
<h:commandLink rendered="#{adminBean.showNext}" action="#{adminBean.goNext}">
<h:outputText> Next ></h:outputText>
</h:commandLink>  
</div>
</td>
</tr>
Instead of hitting Database for every 'Next' click, I wanted to store them in session, like
public static Object getSessionMapValue(String key) {
Log.debug(CLASS_NAME + "getSessionMapValue: key=" +key );
return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(key);
}
public static void setSessionMapValue(String key, Object value) {
Log.debug(CLASS_NAME + "setSessionMapValue: key=" +key );
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key, value);
}
My Questions are :
If I use this approach to store a huge number of search results , will it still be available if the user opens up another tab ? I think so - is not it ?
When the results were more, i tried 'Next' , it did not even call its action method because a new Bean was created (!) and made that showNext as 'false' - What are my options to allow the user to browse thru pages considering my restrictions above ?
Is it okay to use a hidden Bean variable and make it 'true' through javascript when the link was clicked and in the CustomPhaseListener - and in the RESTORE VIEW PHASE - make the showNext as 'true' based on this hidden value? is that a worth approach?
All scoldings and suggestions are welcome.
If you use inputHidden,you may get ClassCast Exception , I am trying like this,not sure yet, if this works
public Boolean getShowNextValue() { if(showNext != null && showNext.getValue()!= null) { log.debug("showNext.getValue() ]" +showNext.getValue()); if(((String)showNext.getValue().toString()).equals("false")) { return false; }else{ return true; } }else{ return false; } }