6 Replies Latest reply on May 19, 2006 1:24 PM by gavin.king

    Lame question about form posting and command links

    najgor

      Problem:

      xhtml part:

      <h:form>
      <h:inputText id="command" value="#{wsTest.command}" required="true" />
      <h:commandButton value="next" action="#{wsTest.next}" class="button" />
      </h:form>
      
      <h:commandLink action="#{wsTest.next}" value="Action 1">
      <f:param name="command" value="NEXT"/>
      </h:commandLink>
      



      seam action:
      @Stateless
      @Local(Foo.class)
      @Name("wsTest")
      @Interceptors(SeamInterceptor.class)
      public class FooAction implements Foo {
      
       @In
       @RequestParameter
       String command;
      
       public String next() {....
      




      Q1) When I do not have a form and have just commandLink, this will work: I have parameter 'command' injected into the action. However, when I add the form on the same page, it stops to work, and I can't even render the page without any exception.

      Is it possible to have both injections (from form and from commandLink) into one action's attribute of type String (Long, Integer...)?


      Q2) However, if I have my custom attribute type instead of String, with light modification of above code, I am able to inject value from form into the nested property (<my_type>.). However, now I am not able to do that using @RequestParameter.

      Is is possible to have nested injection using @RequestParameter and, if yes, how?


      Q3) Since I haven't found 'action' attribute of the <h:outputLink, how to state which seam action will be invoked on link clik?


      Thanx in advance.

        • 1. Re: Lame question about form posting and command links
          denis-karpov

          Hi.

          First, for h:inputText you do not need injection. This code should work. Read more carefully about h:inputText in JSF documentation.

          <h:form>
           <h:inputText id="command" value="#{wsTest.command}" required="true" />
           <h:commandButton action="#{wsTest.next}" class="button" />
          </h:form>
          

          @Name("wsTest")
          public class FooAction implements Foo {
          
           String command;
           public String getCommand(){
           return command;
           }
           public void setCommand(String val){
           command = val;
           }
          
           public String next() {....
          


          Second, Nested injection? What do you mean?

          Third, As i understand outputLink was designed for get requests. So that you do not need 'action' attribute.

          Hope it helps. Denis

          • 2. Re: Lame question about form posting and command links
            najgor

             

            "denis-karpov" wrote:

            Second, Nested injection? What do you mean?


            For example, my Action class has 'user' attribute of custom type User. It has, for example, 'name' property etc, usuall stuff.

            So, I wonder if I can put @RequestParameter annotation on 'user' attribute (that is defined in action) and to put something like this on xhtml:
            <f:param name="user.name" value="John Doe"/>
            


            So this is what I meant by 'nested' injection, or, nested property setting.

            Any help?

            Thanx for the 1st answer, I am going to test it.

            • 3. Re: Lame question about form posting and command links
              najgor

               

              "denis-karpov" wrote:
              Hi.

              First, for h:inputText you do not need injection. This code should work. Read more carefully about h:inputText in JSF documentation.


              Unfortunatelly, it won't work - and, yes, it really seems that it should. I am not able to render page, with the following exception:
              11:45:16,691 ERROR [STDERR] May 19, 2006 11:45:16 AM com.sun.facelets.FaceletViewHandler handleRenderException
              SEVERE: Error Rendering View
              javax.faces.el.PropertyNotFoundException: /wsTest.xhtml @13,74 value="#{wsTest.command}": Bean: $Proxy196, property: command
              at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:58)
               at javax.faces.component.UIOutput.getValue(UIOutput.java:75)
              ...
              


              How to make 'command' property visible? (I have added getters/setters in seam action class).

              Please note that my seam action is also stateless bean.

              thanx in advance

              • 4. Re: Lame question about form posting and command links
                denis-karpov

                 

                How to make 'command' property visible? (I have added getters/setters in seam action class).

                Try to define getter and setter inside Foo interface too.


                For example, my Action class has 'user' attribute of custom type User. It has, for example, 'name' property etc, usuall stuff. So, I wonder if I can put @RequestParameter annotation on 'user' attribute (that is defined in action) and to put something like this on xhtml:
                <f:param name="user.name" value="John Doe"/>
                


                No. You can't.
                But You can do this, for instance ;-)
                <h:inputText id="userName" value="#{wsTest.user.name}"/>


                Denis.

                • 5. Re: Lame question about form posting and command links
                  najgor

                   

                  "denis-karpov" wrote:
                  How to make 'command' property visible? (I have added getters/setters in seam action class).

                  Try to define getter and setter inside Foo interface too.


                  This made the trick, partially:) I didnt put get/set into interface, since I dont like that, however, it is needed if seam action is an ejb component.

                  Moreover, I found out that is not possible to have one action attribute used for both <h:inputText and <f:param. If @RequestParameter exist, seam will first set the attribute from form, and then it will null it, because there is no request paramter with that name.

                  If @RequestParameter do not exist, form will work correctly (as Denis has stated), except, commandLinks will not work.

                  This might be solved by having a new flag for @RequestParameter that will not null-arize actions attribute if request parameter does not exist.

                  Thanx.

                  • 6. Re: Lame question about form posting and command links
                    gavin.king

                    Seam actions that expose value bindings MUST be stateful, not stateless!