jsf - How to avoid exception, <c:if> and <c:catch> -


i'm trying render page, there possibility el expressions generate exceptions. tryed first of all, sorround block < c:if> in such way shows code checking critical condition. saw in case of "error" page redirected again "http 500 - internal server error". tought maybe el expression inside block computed in case, if < c:if> block not shown. sorrounded block < c:catch> read block catch exceptions. added on methods declaration "throws exception". but, again, when critical condition not respected, page redirect 500 error page.

i post xhtml code:

<c:if test="#{!partybean.emptyset}">     <c:catch>      <p:panel id="panel" style="margin-bottom:10px;">              <f:facet name="header" >                         <h:outputlabel value="#{partybean.currentparty.name}" />             </f:facet>             <f:facet name="actions">                         <p:commandbutton id="asktojoin" styleclass="ui-panel-titlebar-icon "                      action="#{joinrequestbean.askforparty(partybean.currentparty)}" value="ask join"/>             </f:facet>              <f:facet name="footer" >                         <p:commandbutton id="pr" action="#{partybean.previus()}" value="previousparty" rendered="#{partybean.hasprevious()}">                         </p:commandbutton>                         <p:commandbutton id="nx" style="margin-right:10px" action="#{partybean.next()}" value="nextparty" rendered="#{partybean.hasnext()}">                         </p:commandbutton>             </f:facet>         <h:panelgrid columns="2">         <h:outputlabel  value="symbol:" />      <h:graphicimage value="#{('/partysymbols/'.concat(partybean.currentparty.symbol))}" width="200" height="171" />          <h:outputlabel for="program" value="program:" />         <h:outputlabel id="program" value="#{partybean.currentparty.program}" />        <h:link id="partyname" outcome="memberlist" value="memberlist">             <f:param  name="partyname" value="#{partybean.currentparty.name}" />          </h:link>     </h:panelgrid>  </p:panel> </c:catch> </c:if> <c:if test="#{partybean.emptyset}"> <h1>there no parties @ moment</h1></c:if> </h:form> </h:body> 

and bean:

@managedbean(name="partybean") @sessionscoped public class partybean { @ejb private partymanagerlocal ejb;    private partydto[] party; int i=0;  @postconstruct private void init() {     i=0;     refresh(); } private void refresh(){     object[] list_o =       ejb.getlistofparty().toarray();     party = new partydto[list_o.length];     for(int i=0;i<list_o.length;i++){         party[i]=(partydto)list_o[i];     }     if(i>=list_o.length)         i=list_o.length; } public boolean isemptyset() {     refresh();     return party.length==0; } public string next() throws exception{     refresh();     if(i<party.length-1)     i++;     return "partyview.xhtml?faces-redirect=true"; } public string previus() throws exception{     refresh();     if(i>0)         i--;     return "partyview.xhtml?faces-redirect=true"; } public boolean hasprevious(){     return i>=1; } public boolean hasnext(){     return i<party.length-1; } public partydto getcurrentparty() throws exception{     return party[i]; }  } 

i apologize show whole code, have no idea mistake. apologize horrible code, @ moment need works.

the critical condition array should not empty. happen array empty in case, need advise user it, instead redirect 500 error page.

thankyou in advance, samuele

you encapsulate want conditionally surrounding code in panelgroup , using rendered attribute.

example

<h:panelgroup rendered="#{partybean.isemptyset}">  <!-- code inside here... -->  <!-- render if isemptyset returns true -->   </h:panelgroup> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -