11 Replies Latest reply on Feb 16, 2007 11:21 AM by hamtho2

    Navigation outcome from bean

      Hi @all,

      when I browsed through the forum I stumbled about a thread, telling how to user navigation outcomes out of a bean and not a view. Unfortunately I cannot find this thread anymore. Can someone give me a hint or a code-example for this?

      Thanks for your help and sorry for the inconvenience

      Thomas

        • 1. Re: Navigation outcome from bean
          • 2. Re: Navigation outcome from bean

            Thank you very much for that. I totally overlooked that part. But it´s still neccessary to have a view-id that is a real xhtml-page. There´s no way to use the outcome of a bean-action for multiple pages, is there? So that I could use the outcome of an action for multiple pages?

            Thomas

            • 3. Re: Navigation outcome from bean

              I'm not quite understanding the question.

              The view-id in pages.xml does not have to be a real page, it can just be to bind an action that is executed when that view is requested but then the action can return an outcome which the page navigation uses to render a different page.

              • 4. Re: Navigation outcome from bean

                sorry - I really did not explain it really clearly.

                The idea is the following:
                I have two different xhtml-pages with an command button on each page referencing to the same ActionBean and calling the same methods, but the result of that action always points to the same result-page. So is it possible to define that whenever this bean is called - doesn´t matter from what page - it should redirect to a defined outcome with only one definition in the pages.xml or navigation.xml?

                • 5. Re: Navigation outcome from bean

                  Try..

                  <page view-id="/*">
                  
                   <navigation from-action="#{myBean.commonAction}">
                   <rule>
                   <redirect view-id="/results.xhtml"/>
                   <rule/>
                   </navigation-case>
                  
                  </navigation-rule>
                  


                  Haven't tried this myself but I think this should work. Basically this says for any page if the "myBean.commonAction" was the action method fired (and it returned a not-null result) by the button click then change the view to the "/results.xhtml" view. The wildcarding is suffix matching so you can make it more specific if you wish.

                  Let me know if this works pls, be useful for future reference.

                  HTH.

                  Mike.

                  • 6. Re: Navigation outcome from bean
                    fernando_jmt

                    Some corrections for the last sample source code:

                    <page view-id="/*">
                    
                     <navigation from-action="#{myBean.commonAction}">
                     <redirect view-id="/results.xhtml"/>
                     </navigation>
                    
                    </page>
                    


                    • 7. Re: Navigation outcome from bean

                      I believe both code samples are above are valid but they do different things. The first will only do the re-direct if the action method returns not-null. The second only if the method returns null. I'm not sure which of these the void case falls into but I suspect the second one.

                      • 8. Re: Navigation outcome from bean

                        Sorry I just spotted the closing </navigation-rule> in my sample which is of course wrong. I'd love to take the blame but I copy-pasted from the Seam docs ;)

                        • 9. Re: Navigation outcome from bean

                          Mike,

                          your idea came pretty close to how it works. Thanks for your help.

                          This is it worked for me now:

                          <page view-id="/*">
                          
                           <navigation from-action="#{myBean.commonAction}">
                           <redirect view-id="/results.xhtml"/>
                           </navigation>
                          
                          </page>


                          But do you know if it is possible to redirect to the page, where I came from as well? If I call an action-method and it returns a String with null, I will be redirected to the page I came from automatically. So is there a way to define this through the pages definition as well?

                          I thought about something like this:

                          <navigation>
                           <rule if="#{myBean.anotherAction}">
                           <redirect view-id="/successfull.xhtml"/>
                           </rule>
                           <rule if="#{not myBean.anotherAction}">
                           <redirect view-id="null"/> <!-- Should be the calling page then -->
                           </rule>
                           </navigation>
                          


                          Is there a way to do something like a switch-case if there might be different-results? In the code-example mentioned above, the anotherAction is probably called everytime I have a new rule.

                          DO you know anything about this?


                          • 10. Re: Navigation outcome from bean

                            sorry - I didn´t refresh the thread before posting. I guess you already told the solution through your explanation. I´ll try this first.

                            • 11. Re: Navigation outcome from bean

                              Yes - it seems, that it works that way. If a null value is returned, I will be redirected to the page I came from if I include the -Tag

                              Thanks for that