5 Replies Latest reply on Jul 22, 2010 5:14 AM by Deesha Singh

    nubie issue: @In injection

    Don Pruitt Newbie

      Hi,


      I have an issue relating to injection. The suspects are Entity:Casino, EJB Bean:UserCasinoListActionBean and JSF: userCasinoListAction.xhtml. The purpose of the bean is to search for a list of Casino entities and return them in a Richfaces dataTable. The data table outjection works fine however I can't seem to get the injection for the search parameter to work. Note that I checked the @Name annotations and tried @In(create=true) without success. If I just dump the injection object to log.info() its a null object and if I use it in the query i get the @In attribute requires non-null value error. I would really appreciate your help as this is kind of making me crazy at this point.




      >>>>>>>>>>>>>>>>>>>>> userCasinoListAction.xhtml <<<<<<<<<<<<<<<<<<<
      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          xmlns:a="http://richfaces.org/a4j"
          template="layout/template.xhtml">
      
      <ui:define name="body">
      
         <!-- implement the search criteria panel -->
         <h:form id="casinoSearch" styleClass="edit">
            <rich:simpleTogglePanel label="Casino Search Filter" switchType="ajax">
               <!-- casino name field -->
               <s:decorate template="layout/display.xhtml">
                  <ui:define name="label">Name</ui:define>
                  <h:inputText id="Name" value="#{casino.name}"/>
               </s:decorate>
               <!-- casino city field -->
               <s:decorate template="layout/display.xhtml">
                  <ui:define name="label">City</ui:define>
                  <h:inputText id="City" value="#{casino.address.city}"/>
               </s:decorate>
          
            </rich:simpleTogglePanel>
         </h:form>
      
         <!-- search and reset button section -->
         <h:form id="userCasinoListActionForm">
               <h:commandButton id="search" value="search!"
                                   action="#{userCasinoListAction.search}"/>
      
         </h:form>
      
         <!--  casino data table -->
         <rich:panel>
            
            <div class="results" id="casinoList">
                             
               <rich:dataTable value="#{casinos}" var="_casino">
                  <!-- name column -->
                  <h:column>
                     <f:facet name="header">Name</f:facet>            
                     #{_casino.name}
                  </h:column>
                  <!-- description column -->
                  <h:column>
                     <f:facet name="header">Description</f:facet>            
                     #{_casino.description}
                  </h:column>
                  <!-- city column -->
            
                  <h:column>
                     <f:facet name="header">Address</f:facet>            
                     <h:outputText value="#{_casino.address.address1}, #{_casino.address.city},
                                    #{_casino.address.district.name},#{_casino.address.country.name}"/>
                  </h:column>
                
               </rich:dataTable>
      
            </div>
         </rich:panel>
      
      
      </ui:define>
      
      </ui:composition>
      
      >>>>>>>>>>>>>>>>>>>>>>>>> UserCasinoListActionBean.java <<<<<<<<<<<<<<<<<<<<<<
      package org.bitwise.blackbox.session;
      
      import java.util.List;
      import javax.ejb.Stateless;
      import javax.persistence.*;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.international.StatusMessages;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.bitwise.blackbox.entity.Casino;
      
      
      @Stateless
      @Name("userCasinoListAction")
      @Scope(ScopeType.SESSION)
      public class UserCasinoListActionBean implements UserCasinoListActionIf
      {
          @Logger private Log log;
      
          @In StatusMessages statusMessages;
          
          @In(value="#{entityManager}")
          EntityManager em;
          
          //@In
          //private Casino casino = new Casino();
          @In(create=true)
          private Casino casino;
          
          @DataModel
          public List<Casino> casinos;
          
          @DataModelSelection
          private Casino selCas;
      
          @Factory("casinos")
          public void search()
          {
              // implement your business logic here
              log.info("userCasinoListAction.search() action called");
              log.info("userCasinoListAction.search() casino: " + casino.getName());
              log.info("userCasinoListAction.search() casino.name:#{casino.name}");
              statusMessages.add("search");
              
              List<Casino> results = em
                              .createQuery("select c from Casino as c where c.name = 'The Sands'")
                                .setMaxResults(25)
                                  .getResultList();
              casinos = results;
          }
          
          public void showDetails()
          {
               //casino.setSelected(true);
          }
      
          // add additional action methods
      
      }
      
      
      >>>>>>>>>>>>>>>>>>>>>>>> Casino.java <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      package org.bitwise.blackbox.entity;
      
      // Generated Jul 10, 2010 10:25:32 AM by Hibernate Tools 3.3.0.GA
      
      import java.util.HashSet;
      import java.util.Set;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import static javax.persistence.GenerationType.IDENTITY;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.OneToMany;
      import javax.persistence.Table;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import static org.jboss.seam.ScopeType.SESSION;
      
      /**
       * Casino generated by hbm2java
       */
      @Entity
      @Name("casino")
      @Scope(SESSION)
      @Table(name = "CASINO", catalog = "blackbox")
      public class Casino implements java.io.Serializable {
      
           /**
            * 
            */
           private static final long serialVersionUID = 8884370758712382089L;
           private Integer id;
           private Address address;
           private String proxyIp;
           private String name;
           private String description;
           private Integer vlevel;
           private String status;
           private Short dflag;
           private Set<Hand> hands = new HashSet<Hand>(0);
      
           public Casino() {
           }
      
           public Casino(Address address, String name) {
                this.address = address;
                this.name = name;
           }
      .
      .
      .
      .
           @Column(name = "name", nullable = false, length = 50)
           @NotNull
           @Length(max = 50)
           public String getName() {
                return this.name;
           }
      
           public void setName(String name) {
                this.name = name;
           }
      }




        • 1. Re: nubie issue: @In injection
          Kevin Sapper Newbie

          Hi Don,


          try @In(required=false) this should solve your problem.

          • 2. Re: nubie issue: @In injection
            Don Pruitt Newbie

            Kevin,


            Thanks for taking a look, unfortunately (required=false) did not address the issue. I turned up the log level with the following line for the casino variable


            selected row: null


            What does this indicate?



            thanks,


            dp





            >>>>>>>>>>>>>> console log <<<<<<<<<<<<<<<<<<<<
            
            21:35:52,311 TRACE [Component] Seam component not found: org.jboss.seam.excel.exporter.showGlobalMessages
            21:35:52,315 TRACE [Component] Seam component not found: init
            21:35:52,320 TRACE [Component] injecting dependencies of: userCasinoListAction
            21:35:52,320 DEBUG [Component] trying to inject with hierarchical context search: statusMessages
            21:35:52,321 DEBUG [Component] trying to inject with EL expression: #{entityManager}
            21:35:52,321 TRACE [Component] instantiating Seam component: entityManager
            21:35:52,321 TRACE [Component] initializing new instance of: entityManager
            21:35:52,321 TRACE [Component] done initializing: entityManager
            21:35:52,321 TRACE [Component] instantiating Seam component: org.jboss.seam.persistence.persistenceContexts
            21:35:52,321 TRACE [Component] initializing new instance of: org.jboss.seam.persistence.persistenceContexts
            21:35:52,321 TRACE [Component] done initializing: org.jboss.seam.persistence.persistenceContexts
            21:35:52,322 TRACE [Component] instantiating Seam component: org.jboss.seam.persistence.persistenceProvider
            21:35:52,322 TRACE [Component] initializing new instance of: org.jboss.seam.persistence.persistenceProvider
            21:35:52,322 TRACE [Component] done initializing: org.jboss.seam.persistence.persistenceProvider
            >>>>>
            21:35:52,322 DEBUG [Component] trying to inject with hierarchical context search: casino
            21:35:52,322 DEBUG [Component] selected row: null
            <<<<<
            21:35:52,322 TRACE [Component] instantiating Seam component: org.jboss.seam.web.parameters
            21:35:52,322 TRACE [Component] initializing new instance of: org.jboss.seam.web.parameters
            21:35:52,322 TRACE [Component] done initializing: org.jboss.seam.web.parameters
            21:35:52,322 TRACE [Component] instantiating Seam component: org.jboss.seam.core.interpolator
            21:35:52,322 TRACE [Component] initializing new instance of: org.jboss.seam.core.interpolator
            21:35:52,322 TRACE [Component] done initializing: org.jboss.seam.core.interpolator
            21:35:52,323 INFO  [UserCasinoListActionBean] userCasinoListAction.search() action called
            21:35:52,323 TRACE [Component] instantiating Seam component: org.jboss.seam.core.interpolator
            21:35:52,323 TRACE [Component] initializing new instance of: org.jboss.seam.core.interpolator
            21:35:52,323 TRACE [Component] done initializing: org.jboss.seam.core.interpolator
            21:35:52,323 INFO  [UserCasinoListActionBean] userCasinoListAction.search() casino: null
            21:35:52,323 TRACE [Component] instantiating Seam component: org.jboss.seam.core.interpolator
            21:35:52,323 TRACE [Component] initializing new instance of: org.jboss.seam.core.interpolator
            21:35:52,323 TRACE [Component] done initializing: org.jboss.seam.core.interpolator
            21:35:52,323 INFO  [UserCasinoListActionBean] userCasinoListAction.search() casino.name: 
            21:35:52,327 INFO  [STDOUT] Hibernate: 
                select
                    casino0_.id as id6_,
                    casino0_.addr_id as addr8_6_,
                    casino0_.description as descript2_6_,
                    casino0_.dflag as dflag6_,
                    casino0_.name as name6_,
                    casino0_.proxy_ip as proxy5_6_,
                    casino0_.status as status6_,
                    casino0_.vlevel as vlevel6_ 
                from
                    blackbox.CASINO casino0_ 
                where
                    casino0_.name='The Sands' limit ?
            21:35:52,328 TRACE [Component] outjecting dependencies of: userCasinoListAction
            21:35:52,328 TRACE [Component] instantiating Seam component: org.jboss.seam.faces.dataModels
            
            >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end console log <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            




            • 3. Re: nubie issue: @In injection
              Craig Bensemann Novice

              I think the problem is the way you have structured your xhtml. You have two forms in it - one containing the search input box and one for the submit button. I think when you click search the browser is only submitting the form with the button in it and not the other form. Try merging the two forms together


                 <h:form id="casinoSearch" styleClass="edit">
                    <rich:simpleTogglePanel label="Casino Search Filter" switchType="ajax">
                       <!-- casino name field -->
                       <s:decorate template="layout/display.xhtml">
                          <ui:define name="label">Name</ui:define>
                          <h:inputText id="Name" value="#{casino.name}"/>
                       </s:decorate>
                       <!-- casino city field -->
                       <s:decorate template="layout/display.xhtml">
                          <ui:define name="label">City</ui:define>
                          <h:inputText id="City" value="#{casino.address.city}"/>
                       </s:decorate>
                  
                    </rich:simpleTogglePanel>
              
                    <h:commandButton id="search" value="search!"
                                       action="#{userCasinoListAction.search}"/>
              
                 </h:form>
              

              • 4. Re: nubie issue: @In injection
                Don Pruitt Newbie

                D'Oh! That's the fix, I can't believe I did this. I really appreciate your help.


                thanks Craig,


                dp

                • 5. Re: nubie issue: @In injection
                  Deesha Singh Newbie

                  I found that giving each form an id allows you to have multiple forms in a page.