1 Reply Latest reply on Jan 17, 2008 2:41 AM by Nicklas Karlsson

    Override page action with commandButton action?

    Jonathan Marston Newbie

      I want an action method to be run when my page is accessed by a redirect or GET, but if an action is performed by the user on the page through a commandLink or commandButton, I want that action method to run. I thought I could do that by creating a page action like this:

      <page view-id="/peopleSearch.xhtml" action="#{peopleSearch.findAllPeople}">
       <navigation>
       <rule if-outcome="viewPerson">
       <redirect view-id="/person.faces"/>
       </rule>
       </navigation>
       </page>


      And a command link on the page like this:
      ...
      <a4j:commandButton value="Search" action="#{peopleSearch.findPeople}" reRender="results"/>
      ...


      But instead of getting the expected result - peopleSearch.findAllPeople being run on initial load, and peopleSearch.findPeople being run when the button is clicked - the method defined in the page action is run every time the page is accessed along with the action from the command button.

      Is there something wrong here, or is this how it is supposed to work? If this is working as designed, how do I achieve my desired functionality?

      Thanks,
      Jonathan