6 Replies Latest reply on Sep 15, 2008 12:41 PM by Nicole Schweighardt

    Outjection ignored - very basic example not running

    Nicole Schweighardt Newbie

      Hello,


      I am new to Seam and tried to run a very simple example but it does not work. After searching in google and in forums too many hours I hope anybody here can help me.


      I use JBoss AS 4.2.2GA, Seam 2.0.2. I work with Eclipse with JBoss Tools.
      I created a New Seam Webproject, an example project from Jboss Tools. That works fine and the example is running.
      Then I only wanted to test outjecting an variable from a session bean. But that does not work. I tried 3 versions:


      1. Version


      This is my basicBean


      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.log.Log;
      
      @Stateful
      @Name("basicBean")
      public class BasicBean implements BasicBeanLocal {
           
          @Logger private Log log;
           
          @In FacesMessages facesMessages;
          
          public void basicBean()
          {
              //implement your business logic here
              log.info("basicBean.basicBean() action called");
              facesMessages.add("basicBean");
          }
          
              @Out
           public String foo = "That is a test";
           
           @Remove @Destroy
           public void destroy() {}
      }



      and this the xhtml-page:


      ...
          <h:messages globalOnly="true" styleClass="message"/>
          
          <rich:panel>
          <f:facet name="header">Welcome!</f:facet>
          <p>
          <h:outputText value="Test: #{foo}"/>
          </p>
        
          </rich:panel>
      ...



      But foo (the Text) isn´t displayed.


      2. Version


      I added a getter-method like someone in a forum told  me:
         


      @Out
      public String foo = "That is a test";
           
      public String getFoo() {
           return foo;
      }




      The xhtml-page is still like in Version 1:


      <h:outputText value="Test: #{foo}"/>  



      But foo (the Text) isn´t displayed.


      3. Version


      The bean is the same as in version 2, with a getter-method.


      In the xhtml-page I call the bean directly:


      <h:outputText value="Test: #{basicBean.foo}"/>



      The result is


      javax.faces.FacesException: javax.el.PropertyNotFoundException: /home.xhtml @18,51 value="Test: #{basicBean.foo}": Property 'foo' not found on type org.javassist.tmp.java.lang.Object_$$_javassist_1




      Can anybody tell me what I am doing wrong?
      Thank you very much.
      NSchweig





        • 1. Re: Outjection ignored - very basic example not running
          Michael Courcy Newbie

          Outjection occurs after you have invoked one of the method of the bean.


          As you invoke none, no outjection happen.

          • 2. Re: Outjection ignored - very basic example not running
            Nicole Schweighardt Newbie

            Hi,


            and thanks for your answer.


            I now invoked the getFoo-method.



            <h:outputText value="Test: #{getFoo}"/>



             
            But nothing happens.


            Then I wrote another method.


            ...
                @Out
                 public String foo = "That is a test";
                 
            
                 public String getFoo() {
                      return foo;
                 }
                 
                 public void testAction(){
                      ...
                 }
            ...



            and invoked it:


              <h:outputText value="Test: #{testAction}"/>
            



            I started JBoss in Debug-mode but the method isn´t invoked by seam.


            Any ideas?


            Thank you
            NSchweig

            • 3. Re: Outjection ignored - very basic example not running
              Tony Herstell Master

              basicBean.getFoo()



              or


              basicBean.foo




              perhaps...


              Check your server startup and see if basicBean is being deployed.

              • 4. Re: Outjection ignored - very basic example not running
                Hans Schlegel Newbie

                Hi Nicole


                You have to check the spec - but you try to outject a non seam-component...


                Please try the following...



                    @Out(required = false, scope = ScopeType.SESSION)
                     public String foo = "That is a test";
                



                Best regards
                hans

                • 5. Re: Outjection ignored - very basic example not running
                  Adrien Orsier Newbie

                  Don't forget to declare your foo's getter and setter into your BasicBeanLocal interface, it's needed since you'be made your component an EJB.
                  Since it's not needed, you can simply remove your @Stateful annotation and not impletement any interface.
                  Still, you'll need public getter and setter for your foo property, and you'll need to reference it like that:


                  #{basicBean.foo}




                  Though, this is not an outjection.
                  Thing is outjection isn't used like that. You often use it to outject a variable you need to use after you've done some business.
                  Something like:




                  @Name("basicBean")
                  public class BasicBean {
                       
                      @Out
                      private String foo = "That is a test";
                       
                      @In FacesMessages facesMessages;
                      
                      public void testMethod()
                      {
                        foo = "test";
                      }
                  }
                  


                  An in a simple page:



                  <s:button value="test" var="#{basicBean.testMethod()}"
                  <h:outputText value="#{foo}"/>



                  This way it will work and demonstrate how it's used.



                  • 6. Re: Outjection ignored - very basic example not running
                    Nicole Schweighardt Newbie

                    Hello everyone


                    thanks for your help!


                    I think Ill read something about seam concepts before I start any other try with outjection..


                    For the moment I only need to display some data with radiobuttons. I know like it works with jsf and managed backing beans; now I want to try the same with seam. If I understood you right, I don´t need any out- or injection.


                    I got an example, were displaying works:


                    Entity:



                    @Entity
                    @Name("product")
                    public class Product implements Serializable{
                    
                         private Integer id;
                         private String name;
                         private String price;
                         private String category;
                         private String shortDescription;
                         private Integer numberOf;
                    ...




                    The Entity has getters and setters for the attributes.


                    Bean:



                    @Name("shopWebSiteBean")
                    public @Stateful class ShopWebSiteBean implements ShopWebSite {
                    
                         @PersistenceContext(unitName="ShopSeam")
                         EntityManager em;
                         
                         private List<Product> games;
                         private Product chosenGame;
                    
                         public List<Product> getGames(){
                              
                                   Query q = em.createQuery("select p from Product p where p.category = :n");
                                   q.setParameter("n","Spiele-Software");
                                   games = (List<Product>)q.getResultList();
                                   return games;
                         }
                    
                         public void setGames(List<Product> games) {
                              this.games = games;
                         }
                    
                         public Product getChosenGame() {
                              return chosenGame;
                         }
                    
                         public void setChosenGame(Product chosenGame) {
                              this.chosenGame = chosenGame;
                         }
                         
                         @Destroy @Remove
                         public void destroy(){     }
                    }




                    JSF:


                    <h:form>
                     <h:selectOneRadio value="#{shopWebSiteBean.chosenGame.name}">
                      <s:selectItems value="#{shopWebSiteBean.games}" var="game" label="#{game.name}"/>
                      <s:convertEntity/>                        
                     </h:selectOneRadio>     
                    <h:commandButton...
                    ...
                    </h:form>




                    I know it from jsf that if you click the h:commandButton the selected radio button value is written in chosenGame.(the setter-method is invoked; )
                    But that does not work here. setChosenGame is not invoked if I click the button.
                    It is the same if I try


                     <h:selectOneRadio value="#{shopWebSiteBean.chosenGame.name}">



                    or


                     <h:selectOneRadio value="#{shopWebSiteBean.chosenGame}">



                    Could anyone help me again?
                    Thank you
                    NSchweig