Search code examples
jsfjsf-2commandbuttonfaces-config

How disable commandbutton if there is no navigation-case in faces-config.xml


do you know if there is an option to set the commandbutton to disabled="true" when there is no matching navigationcase in the faces-config?

At the time I'm learning JSF an writing an Application. The Application consists of various pages. I use an default template in wich I insert the navigatontemplate.

Here is my navigation template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">


<ui:insert name="navigation">
            <nav>           
                <h:panelGroup>
                <h:form>
                <h:commandButton value="GO BACK" styleClass="button" action="GOBACK"/>
                <h:commandButton value="Reset" pt:type="Reset" styleClass="button" action="RESET"/>
                <h:commandButton value="GO FORWARD" action="GOFORWARD" styleClass="button"/>
                </h:form>
            </h:panelGroup>
            </nav>
    </ui:insert>
</ui:composition>

Now in the faces-config I have some navigations rules, for example:

<navigation-rule>
    <display-name>firstPage.xhtml</display-name>
    <from-view-id>/firstPage.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>GOFORWARD</from-outcome>
        <to-view-id>/secondPage.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

Now i want to disable the GOBACK-Button when the user is on the first Page (and no navigation-rule in the faces-config.xml).

Anybody an idea how?

Thanks.


Solution

  • I found now an working solution:

     <h:commandButton value="GO BACK" styleClass="button" disabled="#{view.viewId=='/firstPage.xhtml'} action="GOBACK"/>
    

    The EL-expression view.viewId return the page the user is visting.