java - Strange problem with rendered=true/false issues in JSF -


i having simple annoying issue jsf. have datatable (with simple first next etc paging option) , want populate same page users initial selection.

initial form

<b><h:selectoneradio id="radio1" layout="pagedirection" style="font-weight: bold" value="#{displaynoc.slection}">       <f:selectitem itemlabel="search noc" itemvalue="n" id="selectitem1" />  <f:selectitem itemlabel="search title" itemvalue="t" id="selectitem2" /> </h:selectoneradio></td> <hx:commandexbutton type="submit" image="images/btn_search.jpg" action="#{displaynoc.process_request}" onclick="return validate_listnoc(this.form)"></hx:commandexbutton></b> 

once user select radio button , click "search", populating datatable (which hidden in same page rendered properties false) , paging button (at stage have next button hidden @ time of form load using rendered property) without problem .

<b>search results :<br><br> <h:inputhidden id="text1" value="#{displaynoc.firstrow}" ></h:inputhidden> navigation next button start <hx:commandexbutton type="submit" value="next" action="#{displaynoc.gonext}" rendered="#{displaynoc.render_panel_status}" disabled="#{displaynoc.firstrow + displaynoc.rowperpage >= displaynoc.totalsize}"> </hx:commandexbutton>  <h:datatable border="1" id="table" value="#{displaynoc.wamnoc}" rendered="#{displaynoc.render_status}" var="searchresult" headerclass="row2" rowclasses="row-even,row-odd" cellspacing="6">  <h:column>  <f:facet name="header">   <h:commandlink value="noc_number" style="text-align: center">     </h:commandlink>         </f:facet>          <h:outputtext value="#{searchresult[0]}" />          </h:column> ...................... ....................... </h:datatable> 

my managed bean scope:request in face-config.xml follows (i have getter , setter vars)

@suppresswarnings("unchecked")  public void process_request()  {   setrender_status(true);   setrender_panel_status(true);   wamnocservice wns=new wamnocservice();   list<wam_noc> wnoc= wns.getnocandoccupation(0,10);   //get total size of records   settotalsize(wns.totalrecordavaiable());   settotalpage(wnoc.size()/10);   setrowperpage(10);   setfirstrow(1);   setwamnoc(wnoc);  }   //this action next button in table paging  @suppresswarnings("unchecked")  public void gonext()  {   setrender_status(true);   setrender_panel_status(true);   setrowperpage(10);   system.out.println(firstrow);   firstrow = getfirstrow() + rowperpage;   wamnocservice wns=new wamnocservice();   list<wam_noc> wnoc= wns.getnocandoccupation(firstrow,rowperpage);   setwamnoc(wnoc);   } 

my problem when click gonext() button render_status never set true , never see datatable or button more. admitting new jsf , last thing thought give me such trouble. highly appreciated.

the condition rendered attribtue re-evaluated in subsequent request. since it's depending on request scoped bean garbaged end of response , recreated on next new request, condition turn default , action won't invoked when have in uicommand component or 1 of parents.

in jsf 1.x there several solutions go around this:

  • put bean in session scope. easiest, not user experience whenever enduser opens same page in multiple tabs/browsers on same session.

  • use <h:inputhidden> binding. nasty, more detail can found in this answer.

  • use tomahawk's <t:savestate> retain bean in next request. clean , nice, requires additional component library.

    <t:savestate value="#{displaynoc}" /> 

the jsf 2.0 solution put bean in view scope.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -