3 Replies Latest reply on Mar 11, 2009 6:16 PM by Gilson Tavares

    Could not instantiate Seam component: motorcycleCategService Problem

    ioannis ntantis Newbie

      HI all,


      I am trying to learn seam with jsf hibernate ajax by creating a simple advert application.


      I used seam gen in to create a new project and generate the entity classes (i already had tables in the database).


      After this i am tryign to follow the seam hotel booking example in the online documentation and create a new action to search for soemthjing motorcycle category in my case.


      I have an action class called MotorcycleCategImpl which holds some actions. Code below:



      package com.advert.sbeans;
      
      import java.util.List;
      import java.util.Map;
      import java.util.TreeMap;
      
      import javax.ejb.Remove;
      import javax.persistence.EntityManager;
      import com.advert.ebeans.Motorcycle;
      import com.advert.ebeans.Motorcyclecateg;
      import com.advert.service.MotorcycleCateg;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.security.Restrict;
      import org.jboss.seam.framework.EntityQuery;
      
      @Name("motorcycleCategService")
      @Scope(ScopeType.SESSION)
      public class MotorcycleCategImpl  extends EntityQuery<Motorcyclecateg> implements MotorcycleCateg {
           /**
            * 
            */
           private static final long serialVersionUID = 1L;
           private String searchString;
          private int pageSize = 10;
          private int page  = 2;
      
          @In
          private EntityManager entityManager;
          
          @DataModel
          private List<Motorcycle> motorcycleCats;
          
          @In
          private com.advert.ebeans.Motorcyclecateg motorcyclecateg;
        
           public void find() {
              page = 0;
              if (motorcycleCats != null) {
                   motorcycleCats.clear();
              }
              queryMotorcycles();
          }
           
           @Factory("list")
           public Map<String,Integer> getList() {
                System.out.println("In-method getList");
                Map<String,Integer> list = new TreeMap<String,Integer>();
                list.put("one", 1);
                list.put("two", 2);          
                return list;
           }
           public void it(){          
                System.out.println("In-method it");
           }
      
           
          @SuppressWarnings("unchecked")
          public void queryMotorcycles() {
               motorcycleCats = entityManager.createQuery(
                      "select * from motorcycleCateg")
                      .setMaxResults(pageSize)
                      .setFirstResult(page * pageSize).getResultList();
               
               
      
          }
          
          public String getSearchString() {
                return searchString;
           }
      
           public void setSearchString(String searchString) {
                this.searchString = searchString;
           }
      
           public int getPageSize() {
                return pageSize;
           }
      
           public void setPageSize(int pageSize) {
                this.pageSize = pageSize;
           }
      
           public int getPage() {
                return page;
           }
      
           public void setPage(int page) {
                this.page = page;
           }
      
           public List<Motorcycle> getMotorcycleCats() {
                return motorcycleCats;
           }
      
           public void setMotorcycleCats(List<Motorcycle> motorcycleCats) {
                this.motorcycleCats = motorcycleCats;
           }
           @Destroy
           public void destroy(){
                
           }
           @Remove
           public void remove (){
                
           }
      }



      My entity bean is as follows:


      package com.advert.ebeans;
      // Generated Mar 9, 2009 2:52:56 PM by Hibernate Tools 3.2.2.GA
      
      import java.util.HashSet;
      import java.util.Set;
      import javax.persistence.CascadeType;
      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.OneToMany;
      import javax.persistence.Table;
      import javax.persistence.UniqueConstraint;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.annotations.Name;
      
      /**
       * Motorcyclecateg generated by hbm2java
       */
      @Entity
      @Name("motorcyclecateg")
      @Table(name = "motorcyclecateg", catalog = "advert", uniqueConstraints = @UniqueConstraint(columnNames = "category"))
      public class Motorcyclecateg implements java.io.Serializable {
      
           private Integer motorcycleCategPk;
           private String category;
           private Set<Motorcycle> motorcycles = new HashSet<Motorcycle>(0);
      
           public Motorcyclecateg() {
           }
      
           public Motorcyclecateg(String category) {
                this.category = category;
           }
           public Motorcyclecateg(String category, Set<Motorcycle> motorcycles) {
                this.category = category;
                this.motorcycles = motorcycles;
           }
      
           @Id
           @GeneratedValue(strategy = IDENTITY)
           @Column(name = "motorcycleCategPK", unique = true, nullable = false)
           public Integer getMotorcycleCategPk() {
                return this.motorcycleCategPk;
           }
      
           public void setMotorcycleCategPk(Integer motorcycleCategPk) {
                this.motorcycleCategPk = motorcycleCategPk;
           }
      
           @Column(name = "category", unique = true, nullable = false, length = 100)
           @NotNull
           @Length(max = 100)
           public String getCategory() {
                return this.category;
           }
      
           public void setCategory(String category) {
                this.category = category;
           }
           @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "motorcyclecateg")
           public Set<Motorcycle> getMotorcycles() {
                return this.motorcycles;
           }
      
           public void setMotorcycles(Set<Motorcycle> motorcycles) {
                this.motorcycles = motorcycles;
           }
      
      }



      Now i have a simple xhtml page from where i am trying to call the find method from the MotorcycleCategImpl class (as done the seam documentation roughly).


      My xhtml page searchMotorcycles is as follows:



      <!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:a4j="https://ajax4jsf.dev.java.net/ajax" 
          xmlns:a="http://richfaces.org/a4j"
          template="layout/template.xhtml"> 
           
           <ui:define name="body">
          
          <h:form id="searchCriteria">
          <fieldset> 
             <h:inputText id="searchString" value="#{motorcycleCategService.searchString}" 
                          style="width: 165px;">
               <a:support event="onkeyup" actionListener="#{motorcycleCategService.find}" 
                       reRender="searchResults" />
             </h:inputText>
             &#160;
             <a:commandButton id="findMotorcycles" value="find Motorcycles" action="#{motorcycleCategService.find}" 
                              reRender="searchResults"/>
             &#160;
             <a:status>
                <f:facet name="start">
                   <h:graphicImage value="/img/spinner.gif"/>
                </f:facet>
             </a:status>
             <br/>
             <h:outputLabel for="pageSize">Maximum results:</h:outputLabel>&#160;
             <h:selectOneMenu value="#{hotelSearch.pageSize}" id="pageSize">
                <f:selectItem itemLabel="5" itemValue="5"/>
                <f:selectItem itemLabel="10" itemValue="10"/>
                <f:selectItem itemLabel="20" itemValue="20"/>
             </h:selectOneMenu>
          </fieldset>
          </h:form>
          
          <a:outputPanel id="searchResults">
        <div class="section">
          <h:outputText value="No Hotels Found"
                        rendered="#{motorcycleCats != null and motorcycleCats.rowCount==0}"/>
          <h:dataTable id="hotels" value="#{motorcycleCats}" var="motorcyclecateg" 
                       rendered="#{motorcycleCats.rowCount>0}">
              <h:column>
                  <f:facet name="header">Name</f:facet>
                  #{hot.name}
              </h:column>
              <h:column>
                  <f:facet name="header">Action</f:facet>
                  <s:link id="viewHotel" value="View Hotel" 
                          action="#{motorcycleCats.selectHotel(motorcyclecateg)}"/>
              </h:column>
          </h:dataTable>
          <s:link value="More results" action="#{motorcycleCats.nextPage}" 
                  rendered="#{motorcycleCats.nextPageAvailable}"/>
        </div>
      </a:outputPanel>   
      
      </ui:define>
           
      
      </ui:composition>
      



      Now the problem is that as soon i try to load the above page i get the following error:
      Could not instantiate Seam component: motorcycleCategService


      Any help would be appreciated. Find the stack trace below:


      org.jboss.seam.InstantiationException: Could not instantiate Seam component: motorcycleCategService
           at org.jboss.seam.Component.newInstance(Component.java:2106)
           at org.jboss.seam.Component.getInstance(Component.java:1988)
           at org.jboss.seam.Component.getInstance(Component.java:1950)
           at org.jboss.seam.Component.getInstance(Component.java:1944)
           at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
           at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
           at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
           at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
           at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
           at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
           at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
           at org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
           at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
           at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
           at javax.faces.component.UIOutput.getValue(UIOutput.java:184)
           at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
           at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:284)
           at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
           at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:946)
           at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
           at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
           at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
           at java.lang.Thread.run(Unknown Source)
      Caused by: org.jboss.seam.RequiredException: @In attribute requires non-null value: motorcycleCategService.motorcyclecateg
           at org.jboss.seam.Component.getValueToInject(Component.java:2297)
           at org.jboss.seam.Component.injectAttributes(Component.java:1703)
           at org.jboss.seam.Component.inject(Component.java:1521)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:95)
           at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at com.advert.sbeans.MotorcycleCategImpl_$$_javassist_6.validate(MotorcycleCategImpl_$$_javassist_6.java)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
           at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
           at org.jboss.seam.Component.newInstance(Component.java:2094)