1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Sometimes there are global navigation rules who must be respected too. You can add navigation-rules dynamically while the `action` is executed, so i think there is no standard way! – Grim Sep 23 '14 at 12:26
  • If it is feasible for you to disable the button according to a view bean property? Then you can store the first and last page in the view bean and every time you add a new page, update the "last" page (I guess the first page never changed"). – Smutje Sep 23 '14 at 12:41
  • @Smutje und PeterRader thanks for your help. So there is no best practices? I have found something that also works: I have added following at the command-button in the Navigation-template: `disabled="#{view.viewId== '/firstPage.xhtml'}` . Do you think this is OK and don't break with the conventions? – javaProgrammer Sep 23 '14 at 13:17

1 Answers1

1

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.