1 Reply Latest reply on Jul 10, 2009 5:24 PM by Arbi Sookazian

    Bean could not be created on the Seam Project

    E Ric Newbie

      Hello all,


      i am a newbi in Seam-programming.
      I already could make a Hello Seam on JBoss. But it's only the first step. I still have to learn many things.


      Now i am trying to make an input Text where user can type a name and then beside this Input Text, the name they typed, will be shown.


      So first,of course i make a java project named Bean.
      My Bean.java is


       
      package model; 
      
      public class Bean {
      
           public String text;
           public Bean() {
                
           }
           public String getText() {
                return text;
           }
           public void setText(String text) {
                this.text = text;
           }
      }
      


      And i make a new .xhtml file named hello.xhtml. It looks like this


      <!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"
          template="layout/template.xhtml"
                      xmlns:a4j="http://richfaces.org/a4j">
      
          <ui:define name="body">
      
              <h1>Welcome to Seam!</h1>
              <rich:panel>
                  <h:panelGrid columns="2">
                      <h:graphicImage value="/img/seamlogo.png" alt="Seam logo"/>
                      <s:div styleClass="info">
                         <h:commandButton value="Hello" size="50" style=" width : 129px; height : 60px;"/>
                         <h:inputText value="#{bean.text}"/>
                         <a4j:support event="onkeyup" reRender="rep"/>
                                 <h:outputText value="#{bean.text}" id="rep"/>               
                      </s:div>
                  </h:panelGrid>
              </rich:panel>
      
          </ui:define>
      </ui:composition>




      And into my face-config.xml i add this code


       <managed-bean>
        <managed-bean-name>bean</managed-bean-name>
        <managed-bean-class>model.Bean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
         <property-name>text</property-name>
         <property-class>java.lang.String</property-class>
         <value/>
        </managed-property>
       </managed-bean>
      




      And i didn't add anything onto web.xml.


      I deployed it...
      But in the webbroser i got this :


      An Error Occurred:
      javax.faces.FacesException: Cant instantiate class: model.Bean.. model.Bean


      Stack Trace


      Component Tree


      Scoped Variables



      And in the console there was an error:
      Managedbean bean could not be created.



      Could anyone please help me?
      I am really new here ..


      It would be my pleasure to get any feedback from you.


      Thank you


        • 1. Re: Bean could not be created on the Seam Project
          Arbi Sookazian Master

          change this:


          <h:commandButton value="Hello" size="50" style=" width : 129px; height : 60px;"/>



          to:


          <h:commandButton value="Hello" action="#{foo.bar}" size="50" style=" width : 129px; height : 60px;"/>



          In the Unified EL (expression language) above, 'foo' is the name of your Seam component and 'bar' is a business method (public) in your JavaBean or SFSB (if using SFSB, the method must be defined in your local interface).


          so your backing bean would look something like this for a JavaBean:


          @Name("foo")
          public class Foo {
             public void bar() {
                //do stuff
             }
          }



          or this for a SFSB:


          @Name("foo")
          @Stateful
          public class Foo implements FooLocal {
             public void bar() {
                //do stuff
             }
          
             @Remove
             public void destroy(){}
          }



          With JBoss EL, you can pass a param to the action method as well:


          action="#{foo.bar(baz)}"



          One of the purposes of Seam was to eliminate the XML in faces-config.xml you wrote.  You don't need to do that anymore when you use JSF/Seam/EJB3/JavaBean.


          Look at the code for the hotel booking example very closely.  Conversation management/modeling and bijection are two of the most difficult aspects of Seam to learn...


          Read one of the Seam books in their entirety (it's in your best interest :).