8 Replies Latest reply on Aug 9, 2006 10:20 PM by ssilvert

    Seam URLs and request processing

    dpocock


      Hi, previously I have been using Struts and am now considering using Seam for my web applications.

      In Struts, the requested URL is used to find an action in the struts-config.xml (controller configuration), and Struts then invokes my Action class and finally displays the JSP or other view component.

      In Seam/JSF, how does this logic work? I've looked at the Jave 5 EE tutorial on JSF, and the model they have for request processing, but it makes no mention of Seam.

      Can someone help us former Struts users by explaining some of these issues:

      a) when I go to a Seam URL, e.g. seam-registration/register.seam, is the URL processed by JSF or by Seam?

      b) for the register.seam URL, does JSF/Seam simply look for a JSP file with the same name, e.g. does it look for register.jsp, or if I put the URL help.seam, does it look for help.jsp? Or is there some more complicated decision making that helps it decide which page to use or which bean to invoke?

      c) is there any direct relationship between the Seam component names (e.g. the session bean annotated with @Name("register")) and the URL /register.seam?

      d) I notice that for the dvd.xhtml page in the DVD example, you explicitly point to an action by using the pages.xml - but for other pages, you have nothing in pages.xml. Why is it that you have to explicitly put this code in pages.xml for some pages and not for others?

      e) Could someone possibly add a section to the Seam documentation to discuss the URLs, and what the average developer needs to know about the relationship between a URL ending in .seam and the underlying beans and JSP.

        • 1. Re: Seam URLs and request processing
          pmuir

          This is a facelets-centric response:

          a) when I go to a Seam URL, e.g. seam-registration/register.seam, is the URL processed by JSF or by Seam?


          JSF, but Seam has hooks into JSF that do magic

          c) is there any direct relationship between the Seam component names (e.g. the session bean annotated with @Name("register")) and the URL /register.seam?


          No, to refer to properties from register in register.seam you would have to use #{register.property}

          I notice that for the dvd.xhtml page in the DVD example, you explicitly point to an action by using the pages.xml - but for other pages, you have nothing in pages.xml. Why is it that you have to explicitly put this code in pages.xml for some pages and not for others?


          JSF is a component based framework. pages.xml adds some action framework ability by allowing an action to be run when a page is loaded. If an action is specified in pages.xmlit is run before the page is processed.

          • 2. Re: Seam URLs and request processing
            raja05

            The rest have been answered in the other post. Ill try and answer the one that isnt answered there.

            "dpocock" wrote:

            b) for the register.seam URL, does JSF/Seam simply look for a JSP file with the same name, e.g. does it look for register.jsp, or if I put the URL help.seam, does it look for help.jsp? Or is there some more complicated decision making that helps it decide which page to use or which bean to invoke?


            The default View handler extension(indicated by ViewHandler.DEFAULT_SUFFIX) is .jsp. So any url that you have will get replaced with a .jsp and is looked for. If you want this to be changed, you can specify a javax.faces.DEFAULT_SUFFIX in your web.xml's init-param and give a suitable extension.


            • 3. Re: Seam URLs and request processing
              dpocock

               

              "raja05" wrote:
              The rest have been answered in the other post. Ill try and answer the one that isnt answered there.

              "dpocock" wrote:

              b) for the register.seam URL, does JSF/Seam simply look for a JSP file with the same name, e.g. does it look for register.jsp, or if I put the URL help.seam, does it look for help.jsp? Or is there some more complicated decision making that helps it decide which page to use or which bean to invoke?


              The default View handler extension(indicated by ViewHandler.DEFAULT_SUFFIX) is .jsp. So any url that you have will get replaced with a .jsp and is looked for. If you want this to be changed, you can specify a javax.faces.DEFAULT_SUFFIX in your web.xml's init-param and give a suitable extension.


              Thanks for these quick responses.

              On the issue of URL's, are you saying that the .seam extension is simply an arbitrary choice, and that I could just as easily use .faces, .do or even .elvis, provided that my web.xml associates such pages with the FacesServlet? Or would Seam be affected if .seam was not used?

              • 4. Re: Seam URLs and request processing
                gavin.king

                yes, .elvis is supported

                • 5. Re: Seam URLs and request processing
                  dpocock

                   

                  "gavin.king@jboss.com" wrote:
                  yes, .elvis is supported


                  and could I define a `virtual' page in pages.xml, e.g. a page that doesn't actually exist, but where the action listener would decide the page to be rendered, e.g:

                  <page view-id="/virtual.xhtml" action="#{switchboard.chooseAPage}" />

                  virtual.xhtml being non-existant, and switchboard.chooseAPage being a stateless session bean method that returns the real view-id to display.

                  The user would possibly enter the URL ending in /myapp/virtual.elvis, and #{switchboard.chooseAPage} might return a value such as eminem.jsp or britney.xhtml

                  The result of all this is that the URLs no longer have a 1-1 mapping to actual files, much like in Struts.

                  • 6. Re: Seam URLs and request processing
                    gavin.king

                    Absolutely, this pattern is mentioned in the documentation.

                    • 7. Re: Seam URLs and request processing
                      dpocock

                       

                      "gavin.king@jboss.com" wrote:
                      Absolutely, this pattern is mentioned in the documentation.



                      I tried changing my URLs to end with `.elvis' instead of `.seam'. I notice that tags like <h:commandLink> now generate URLs with the new ending. How do these tags know that I am using this new pattern? Do they just look at the current URL being processed?



                      • 8. Re: Seam URLs and request processing
                        ssilvert

                         

                        "dpocock" wrote:
                        "gavin.king@jboss.com" wrote:
                        Absolutely, this pattern is mentioned in the documentation.



                        I tried changing my URLs to end with `.elvis' instead of `.seam'. I notice that tags like <h:commandLink> now generate URLs with the new ending. How do these tags know that I am using this new pattern? Do they just look at the current URL being processed?



                        This is done by JSF. The tags don't know anything. They defer to the ViewHandler to build the URL. Different view handlers might do different things, but it typically does tricks like looking at the incoming request and reading your web.xml. For portlets, the URL ultimately comes from the Portal.

                        Stan