1 Reply Latest reply on Apr 24, 2009 1:19 AM by Dan Allen

    Differentiate between buttons without action in pages.xml

    Konstantin Konstantinopel Newbie

      Hi @ all!


      It is possible to define a button/link in an JSF page, which has no informations about his action/pageflow? I want to define the action and the pageflow only inside the pages.xml.


      I've defined two buttons like this:


      <h:commandButton id="viewButton" value="Click here to View the current entity."/>
      <h:commandButton id="editButton" value="Click here to edit the current entity."/>
      



      But I've no idea how I can differentiate between the two buttons in pages.xml, because I know only the differentiate between from-action, if-outcome, and if.


      I want to have something like this:


      <page view-id="/mypage.xhtml">
         <navigation>
            <rule> <!-- for view button -->
               <action execute="#{mySessionBean.doSomethingForView()}" />
               <redirect view-id="/viewpage.xhtml"/>
            </rule>
      
            <rule> <!-- for edit button -->
               <action execute="#{mySessionBean.doSomethingForEdit()}" />
               <action execute="#{mySessionBean.doAnotherForEdit()}" />
               <redirect view-id="/editpage.xhtml"/>
            </rule>
         </navigation>
      </page>
      



      It is possible or do I have to specify an (empty) action for each button?


      Cornelius

        • 1. Re: Differentiate between buttons without action in pages.xml
          Dan Allen Master

          You can distinguish between the two buttons by assigning a logical outcome to each one:


          <h:commandButton id="viewButton" action="view" value="Click here to View the current entity."/>
          <h:commandButton id="editButton" action="edit" value="Click here to edit the current entity."/>



          Then you can refer to these outcomes in your navigation rules:


          <page view-id="/mypage.xhtml">
             <navigation>
                <rule if-outcome="view">
                   <redirect view-id="/viewpage.xhtml"/>
                </rule>
          
                <rule if-outcome="edit">
                   <redirect view-id="/editpage.xhtml"/>
                </rule>
             </navigation>
          </page>



          However, you cannot execute actions inside of rules. The best you can do is raise an event which an observer will observe and execute logic.