1

I'm trying to render a page, but there is the possibility that some EL Expressions will generate some exceptions. So I tryed first of all, to sorround by block with a < c:if> in such the way that it shows the code only by checking the critical condition. But I saw that in case of "error" my page was redirected again as a "HTTP 500 - Internal Server Error". So I tought that maybe the EL Expression inside the block where computed in any case, also if the < c:if> block where not shown. So I sorrounded my block with a < c:catch> as i read that this block will catch the exceptions. So I also added on all the methods the declaration "throws Exception". But, again, when the critical condition is not respected, my page will be redirect to the 500 Error page.

I post my 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 to 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 are no parties at the moment</h1></c:if>
</h:form>
</h:body>

And my 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 to show to you my whole code, but i have no idea about where is the mistake. Then I also apologize about my horrible code, but at the moment i just need that it works.

The critical condition is that my array should be not empty. Could happen that my Array will be empty but in that case, i need to advise the user about it, instead redirect to the 500 Error page.

Thankyou in advance, Samuele

Sam
  • 313
  • 4
  • 21

1 Answers1

0

You could encapsulate what you want conditionally by surrounding the code in a panelGroup and using the rendered attribute.

Example

<h:panelGroup rendered="#{PartyBean.isEmptySet}">

<!-- Code inside here... -->

<!-- This will render if isEmptySet returns true -->


</h:panelGroup>
Josef E.
  • 2,179
  • 4
  • 15
  • 30