4 Replies Latest reply on Apr 22, 2009 10:01 PM by gonorrhea

    I don't get how @In and @Out work

    kenclark

      I have what I guess is a basic question about how injection/outjection works.  I have run into similar problems before.  What is happening is I have an attribute on an @Stateful session bean that I have marked @In and @Out:



      @Stateful
      @Name("customDataAction")
      public class CustomDataAction implements CustomDataActionLocal
      {
          @Out(scope=ScopeType.CONVERSATION,required=false)
          @In (required=false)
          private String customDataValidValuesText;
      ...
      



      and a web page that uses the attribute in a textArea:



          <h:inputTextarea value="#{customDataValidValuesText}" rows="6" cols="30"
            rendered="#{customDataConfiguration.customDataType.customDataTypeCode=='select'}"/>
      
      



      What I find is that when I enter text in the text area and click the button that calls the action method on the same component, the value of the attribute customDataValidValuesText is null.


      As far as I understand it, I should get the value entered by the user, but it does not seem to work that way.  What is it that I am missing about how this should work?


      Thanks,
      ken

        • 1. Re: I don't get how @In and @Out work
          kenclark
          I believe I have worked around this in the past by using a java bean type object instead of the direct usage of a String.

          So instead of the above, I would do:

          @Out(scope=ScopeType.CONVERSATION,required=false)
          @In (required=false)
          private MyBean myBean;

          where MyBean has an attribute customDataValidValuesText with getters and setters, and then update the page code as:


          <h:inputTextarea value="#{myBean.customDataValidValuesText}" rows="6" cols="30"
                rendered="#{customDataConfiguration.customDataType.customDataTypeCode=='select'}"/>


          Is this a proper workaround?  Can anyone explain why this is necessary?

          Thanks,
          ken
          • 2. Re: I don't get how @In and @Out work
            gonorrhea

            typically there is a getter/setter public method for each HtmlInput* control.


            also, b/c a SFSB has CONVERSATION as default scope, the @Out does not need to explicitly define CONVERSATION b/c it defaults to the scope of the component.


            also note that outjection only occurs if the public method completes successfully...

            • 3. Re: I don't get how @In and @Out work
              kenclark

              Thanks for the response.



              Arbi Sookazian wrote on Apr 22, 2009 18:42:


              typically there is a getter/setter public method for each HtmlInput* control.


              I am not sure what you are saying here?



              also note that outjection only occurs if the public method completes successfully...


              In this case, its the injection that does not work as I expect (I get nulls, even though I have entered text in the text area connected to my injected attribute)


              Thanks,
              ken

              • 4. Re: I don't get how @In and @Out work
                gonorrhea

                you need to read a Seam book, ref doc or look at the booking example source code.


                in backing bean:


                public void setCustomDataValidValuesText(String foo){
                     this.customDataValidValuesText = foo;
                }
                
                public String getCustomDataValidValuesText(){
                     return customDataValidValuesText;
                }
                



                in .xhtml:


                <h:inputTextarea value="#{customDataAction.customDataValidValuesText}"/>



                in the value attribute EL, you must always reference the Seam component name, followed by dot operator (for invoking methods), followed by context variable name (JSF/Seam will invoke the appropriate getFoo() or setFoo() method depending on phase of JSF cycle).


                e.g., value=#{componentName.myMethod}


                The exception to this rule is if you're using the @DataModel to outject a ListDataModel for a dataTable component.  Then the following is allowed:


                <rich:dataTable value="#{myList}" var="foo"/>