3 Replies Latest reply on Jan 14, 2010 2:20 AM by Bruno Lellis

    Page navigation - better approach

    Bruno Lellis Newbie

      Hello everybody!
      Imagine that I have a file called customers.xhtml (customers.seam) and this file may be accessed through sales.xhtml or whatever.xhtml.


      What is the better approach to redirect (like a back button) users from customers.xhtml to sales.xhtml or whatever.xhtml?


      Currently, in CustomersBean, I have an if to treat what string will be returned (configured in pages.xml), but this is sounds ugly and will get confused.


      Thanks!

        • 1. Re: Page navigation - better approach
          Daniel Rowe Newbie
          I use an "f:param" inside Seam link -- the f:param sets the name of the "from" page.

          So, for example, in your case, it might look like this:

          sales.xhtml:
              <s:link id="foo"
                  value="Foobar"
                  view="/customers.xhtml">
                <f:param name="fromPage" value="sales"/>
              </s:link>

          customers.xhtml:
              <s:button
                      id="back"
                      value="Back"
                      view="/#{empty fromPage ? 'someDefaultPage' : fromPage}.xhtml">
              </s:button>

          pages.xml:
              <page view-id="/customers.xhtml" login-required="true">
                  <param name="fromPage"/>
              </page>

          • 3. Re: Page navigation - better approach
            Bruno Lellis Newbie

            It works:



            pages.xml


                    <page view-id="/teste/*">
                            <begin-conversation join="true" />
                            
                            <param name="fromPage" value="#{testeBean.fromPage}" />
                    </page>
            
                    <page view-id="/teste/page1.xhtml">
                    <navigation>
                            <rule if-outcome="page_3">
                                            <redirect view-id="/teste/page3.xhtml">
                                                    <param name="fromPage" value="page_1" />
                                            </redirect>
                                    </rule>
                    </navigation>
                    </page>
            
                    <page view-id="/teste/page2.xhtml">
                    <navigation>
                            <rule if-outcome="page_3">
                                            <redirect view-id="/teste/page3.xhtml">
                                                    <param name="fromPage" value="page_2" />
                                            </redirect>
                                    </rule>
                    </navigation>
                    </page>
            
                    <page view-id="/teste/page3.xhtml">
                            
                    <navigation>
                            <rule if-outcome="page_1">
                                            <redirect view-id="/teste/page1.xhtml"/>
                                    </rule>
                            <rule if-outcome="page_2">
                                            <redirect view-id="/teste/page2.xhtml"/>
                                    </rule>
                    </navigation>
                    </page>
            




            /teste/page1.xhtml:


                            <h1>page 1</h1>
                            <h:form>
                                    <h:commandLink value="page 3" action="page_3" />
                            </h:form>
            



            /teste/page2.xhtml:


                            <h1>page 2</h1>
                            <h:form>
                                    <h:commandLink value="page 3" action="page_3" />
                            </h:form>
            



            /teste/page3.xhtml:


                            <h:form>
                            from: <h:outputText value="#{fromPage}" />
                            <h:commandLink value="voltar - back" action="#{testeBean.back}" />
                            </h:form>
            



            TesteBean.java:


            @Name("testeBean")
            @Scope(ScopeType.CONVERSATION)
            public class TesteBean implements Serializable {
            
                    private String fromPage;
            
                    public String back() {
                            return fromPage;
                            
                    }
            
            
                    public String getFromPage() {
                            return fromPage;
                    }
            
                    public void setFromPage(String fromPage) {
                            this.fromPage = fromPage;
                    }
            
            }
            
            




            and, IMHO, it is easier to understand.