4 Replies Latest reply on Sep 19, 2008 11:10 AM by accless

    Creat and parameter injection

    bashan

      It seems link when defining a parameter in pages.xml the value injected to the bean property is not available in the @Create method. Is is a correct behavior?

        • 1. Re: Creat and parameter injection
          accless

          This is a correct and logical behavior.
          Your Create-Method is invoked, right after SEAM instantiated your Component! When your Component is created, the request values have not been applied yet!


          the workflow for a get-Request:




          1. incoming Request to server

          2. seam-instantiates all necessery components (referenced in your xhtml and pages.xml)

          3. start of normal jsf-lifecylce (applyValues from Request, validation, etc.) and scanning of pages.xml



          greetings

          • 2. Re: Creat and parameter injection
            bashan

            Thanks,


            I pretty much know that in this phase apply value has not taken place yet. But I though this is the whole idea behind there param. Having the parameter values ready for you.
            For this reason obviously I will be using RequestParameter annotation instead. and here comes the question: why not always use RequestParameter? The parameter is the always from the very begining, so why use param in pages.xml which limits you in case of Create annotation?

            • 3. Re: Creat and parameter injection
              accless
              Dont forget.

              each (Ajax-)Request to your sfsb/pojo will cause seam to inject the request-Parameter again and again.

              Annotate your set-Method with a RequestParameter Annotation and u can preserve your (initial) request-parameter very easily. This is especially helpful, if your sfsb/pojo contains some methods, which are invoked via AJAX (its not always sure (more or less a pitfall) that the ajax-request encode the Request-Parameter again and again)

              @RequestParameter
              public void setRequest(Long idXXX) {
                  if (idXXX != null)
                     this.idXXX = idXXX;
              }


              greetings
              • 4. Re: Creat and parameter injection
                accless

                i forgot to mention, even if u use RequestParameter-Annotation, the values are applied after the creation of your bean!