4 Replies Latest reply on Sep 28, 2011 12:20 PM by pozezefat

    Simple navigation problem

    pozezefat

      Hello,


      I've a very simple navigation problem.
      I've got an xhtml file liste.xhtml and a liste.page.xml file.
      I would like to redirect users when they try to access directly this page and the proper data have not been initalized.


      In my liste.page.xml, I've done somrthing like that :


      <navigation>
        <rule if="#{action.datas == null or action.datas.isEmpty()}">
          <redirect view-id="/pages/empty.xhtml"/>
        </rule>
      </navigation>



      But it seems to be ignored.
      When I add an action tag at the beginning of the file, the navigation works, but the method isn't useful (it's empty) :


      <action execute="#{action.nothing()}"/>
      
      <navigation>
        <rule if="#{action.datas == null or action.datas.isEmpty()}">
          <redirect view-id="/pages/empty.xhtml"/>
        </rule>
      </navigation>



      Is there a cleaner way to do that ?


        • 1. Re: Simple navigation problem
          cosmo

          Also you can check if the conditions are fulfilled at the <action execute part. If not throw an exception and then catch it with pages.xml

          • 2. Re: Simple navigation problem
            nathandennis

            i was under the impression that these navigations were action based, but i might be wrong. why not just handle it in the action you call in your bean? you are already calling it.


            <action execute="#{action.nothing()}"/>
            



            looks like you would want to do this anyway because if its not initialized than you would probably want to initialize it instead of dealing with a NPE in your xml. NPE in xml are bad juju. move it in a bean, wrap it in a try. configure the redirect path in xml as a resource if you want, complete your business logic then put the right stuff on the screen.

            • 3. Re: Simple navigation problem
              nathandennis

              someone needs to do something about this spam.. i hate them.. but its time for CAPTCHA

              • 4. Re: Simple navigation problem
                pozezefat

                You must be right.
                As my action is initilized, I don't really need this page.xml file, I can do it all in the method.
                Well, in fact, it does not really need to be initialized, I could have written :


                <rule if="#{action == null or action.datas == null or action.datas.isEmpty()}">



                But it needs to be on the page they will be redirected, so my problem is kinf of solved.


                Thanks.