11 Replies Latest reply on Jul 24, 2008 11:42 PM by pdpantages

    Can't make page parameter work

    pdpantages

      Hello Forum,


      I am using:
      Jboss 4.2.2.GA
      Seam 2.0.1.GA
      Richfaces 3.2.1.GA


      I was trying to use a page parameter as described in the manual.


      I created my entry in pages.xml



      <page view-id="/view/utils/attachment.xhtml" action="#{mediaAction.myAction}">
         <param name="mediaid" value="#{mediaAction.mediaid}" />
      </page>
      
      



      A simple test class


      @Scope(STATELESS)
      @Name("mediaAction")
      public class MediaActionBean {
          
          /** Creates a new instance of MediaActionBean */
          public MediaActionBean() {
              System.out.println("PDP MediaActionBean CTOR");
          }
      
          private String mediaid;
      
          public String getMediaid() {
              System.out.println("PDP GET meidaId " + mediaid );
              return this.mediaid;
          }
      
          public void setMediaid( String mediaid ) {
              System.out.println("PDP SET meidaId " + mediaid );
              this.mediaid = mediaid;
          }
      
          public void myAction()
          {
              System.out.println("PDP myaction");
          }
      
      }
      




      Test page contains:


      <h:outputText value="Attachment id #{mediaAction.mediaid}"/>    
      




      However, when I test it. I never see the setter for mediaid, or the method for the
      page action ever called. I see the CTOR and a call to getMediaid()
      which returns null. The bookmark/URL I use to test is constructed like so:



      http://172.30.0.204:8080/client/view/utils/attachemnt.seam?mediaid=7ac37dd2-454d-4d18-a560-9c498894dba1
      
      



      I must have done something wrong, but I can't seem to see it.


      Any hints will be greatly appreciated.



      Thanks, PdP

        • 1. Re: Can't make page parameter work
          ericjava.eric.chiralsoftware.net

          I think the stateless scope is a problem.  Each time the stateless object is referred to, it can be referring to a brand-new one that has no knowledge of the past.   When you say:


          <param name="mediaid" value="#{mediaAction.mediaid}" />



          you are referring to one mediaAction object.  When you later say:


          <h:outputText value="Attachment id #{mediaAction.mediaid}"/>



          you are referring to a new mediaAction that has not been initialized.


          ------------------


          JBoss Seam seminar

          • 2. Re: Can't make page parameter work
            pdpantages

            Hello Eric, thank you for the suggestions.


            Stateless might be an issue, but I don't think that it is the root of this problem. I have tried an @Stateful MediaActionBean, and the result is basically the same; the page parameter is not set and the page action is not called.


            I have found that an @RequestParameter on the mediaId will set it (without calling the setter method; I see no println output), but the page action is still not called.


            One of the examples in the manual (Example 1.34/35) uses a stateless scope.


            PdP

            • 3. Re: Can't make page parameter work
              ericjava.eric.chiralsoftware.net

              Are you sure the view id: view-id="/view/utils/attachment.xhtml" in pages.xml is correct?  I'm guessing that the /view part of the path shouldn't be there?

              • 4. Re: Can't make page parameter work
                ericjava.eric.chiralsoftware.net

                And by the way, if your class looks like this:


                @RequestParameter private String mediaid;
                public void setMediaid(String s) { ...



                then the setter won't be called.  It will set mediaid using reflection.


                You could say it as:


                private String mediaid;
                @RequestParameter public void setMediaid(String s) { ...



                and the setter should be used then.

                • 5. Re: Can't make page parameter work
                  pdpantages

                  Hello again,


                  I did not think of moving the @RequestParameter, thank you....
                  I may be able to get by with this, as I can put some code in the setter to initialize the bean.
                  (what I had planned to do with the page action).


                  Wrt. the view-id in pages.xml, I am certain that it is correct. My view root is /client, not /client/view. Also, I have other, similar entries in pages.xml, mostly for use in the seam-workspaces page(conversation switcher), that work correctly.


                  PdP


                  • 6. Re: Can't make page parameter work
                    ericjava.eric.chiralsoftware.net

                    If your view root is /client and not /client/view, then how could the view ID /view/utils/attachment.xhtml be correct?

                    • 7. Re: Can't make page parameter work
                      pdpantages

                      Hi Eric, I guess I should have said that my context-root is /client ....
                      E.g., in application.xml,


                      <context-root>/client</context-root>
                      


                      PdP

                      • 8. Re: Can't make page parameter work
                        ericjava.eric.chiralsoftware.net

                        And so within the /client directory, you have a view directory?  I think the Seam-gen apps have a view directory, but the view path element itself doesn't show up in the WAR directory.

                        • 9. Re: Can't make page parameter work
                          pdpantages

                          Hello again,


                          I did not use seam-gen for this project. In the war file, the path starts with view dir. E.g, this is what is in the war file:


                            /build/new/centina/sa/client/exploded-archives/client.war:
                            total used in directory 112 available 32982816
                            drwxr-xr-x 10 pdp pdp  4096 2008-07-14 22:09 .
                            drwxr-xr-x  5 pdp pdp  4096 2008-07-14 22:08 ..
                            -rw-r--r--  1 pdp pdp    71 2008-07-14 22:09 components.properties
                            drwxr-xr-x  2 pdp pdp  4096 2008-07-14 22:09 css
                            drwxr-xr-x  2 pdp pdp 12288 2008-07-14 22:09 img
                            -rw-r--r--  1 pdp pdp    91 2008-07-14 22:09 index.html
                            drwxr-xr-x  4 pdp pdp  4096 2008-07-14 22:09 js
                            drwxr-xr-x  2 pdp pdp  4096 2008-07-14 22:09 META-INF
                            drwxr-xr-x  3 pdp pdp  4096 2008-07-14 22:09 partner
                            drwxr-xr-x  2 pdp pdp  4096 2008-07-14 22:09 reports
                            drwxr-xr-x 15 pdp pdp  4096 2008-07-14 22:09 view
                            drwxr-xr-x  5 pdp pdp  4096 2008-07-14 22:09 WEB-INF
                          


                          The url (see first post) does take me to the proper page; I think the path component is OK.

                          • 10. Re: Can't make page parameter work
                            mail.micke

                            Hiya


                            Looks to me like there is a typo: attachemnt in the link you posted in the first post vs. attachment in pages.xml


                            - micke

                            • 11. Re: Can't make page parameter work
                              pdpantages

                              Why, thank you micke, for that keen observation.  This was the problem all along :(.


                              Also thanks to Eric for taking a look.


                              PdP