jsf - How to initialize variables in a session scoped bean -


i have 2 booleans controls render of components, problem variables saves there last state until session expires, i

<f:facet name="footer">   <p:commandbutton action="#{personbean.report}" ajax="false" value="publish"                             rendered="#{personbean.reportmode}" icon="ui-icon-check" />   <p:commandbutton action="#{personbean.saveediting}" ajax="false" value="save"                             rendered="#{personbean.editmode}" icon="ui-icon-check" /> </f:facet> 

the bean session scoped , has following attributes:

@managedbean(name = "personbean") @sessionscoped public class reportperson { private boolean editmode; private boolean reportmode;  } 

the bean contains these method changes values of booleans:

public string editperson() {     system.err.println("edit missing person");     editmode = true;     reportmode = false;     return "reportnewperson"; } 

the problem these values remains until session expires , result components renders incorrectly

if using session scoped bean should initialize them in constructor like

public reportperson(){ //let want show report mode default editmode = false; reportmode = true; } 

after , create 2 methods

public void ineditmode(){            editmode = true;            reportmode = false; }  public void inreportmode(){            editmode = false;            reportmode = true; } 


now call #{reportperson.editmode} , #{reportperson.reportmode} on rendering cpomponent , call these methods inreportmode() , ineditmode getting bean sessionmap in backing bean.you may bean sessionmap this

reportperson rp = facescontext.getcurrentinstance().getexternalcontext().getsessionmap().get("reportperson"); 

from , can current bean , can invoke

rp.ineditmode(); 


using session scope , have change them logic because keep state remain during whole session.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -