8 Replies Latest reply on Feb 23, 2011 10:06 AM by Rafael Abreu

    How to bind a JPA entity as a backing bean for a simple CRUD screen

    infinity2heaven Novice

      Very simple use case: A Create screen for a CRUD operation.



      SLSB


      @Stateless(name="memberRegistration")
      public class MemberRegistrationImpl
           implements MemberRegistration {
      
           @PersistenceContext
           private EntityManager em;
      
           @Inject
           private Event< Member > event;
      
              
              // backing/binding bean used in JSF page. Also a JPA entity
              // @Model also doesn't work. Don't think I can @Inject an entity object either 
           private Member member = new Member();
      
           public String register() {
      
                em.persist( member );
      
                event.fire( member );
      
                return "home";
      
           }
      
           
           public Member getMember() {
      
                return member;
           }
      
           public void setMember(
                Member member ) {
      
                this.member = member;
           }
      
      }




      jsf page:




      <h:form id="registration" prependId="false">
           <h:panelGroup styleClass="" layout="block">
                <div class="prompt">#{label}</div>
                <h:panelGrid columns="1">
              first name:
              <h:inputText value="#{memberRegistration.member.firstName}" required="true" />
              last name:
              <h:inputText value="#{memberRegistration.member.lastName}" required="true" />
              email:
              <h:inputText value="#{memberRegistration.member.email}" required="true" />
               phone number:
              <h:inputText value="#{memberRegistration.member.phoneNumber}" />
               dob:
              <h:inputText value="#{memberRegistration.member.dob}" required="true" />
               notes:
              <h:inputTextarea value="#{memberRegistration.member.notes}" />
      
                </h:panelGrid>
                <h:panelGroup>
                     <h:commandButton id="lsubmitButton" value="Save"
                          action="#{memberRegistraion.save}" />
                </h:panelGroup>
           </h:panelGroup>
      </h:form>







      On page load, I get this error


      Error Rendering View[/patient-registration.xhtml]: javax.el.PropertyNotFoundException: /patient-registration.xhtml @20,95 value="#{memberRegistration.member.firstName}": The class 'xxx.demoportal.controller.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$Users$xxx$dev$servers$jboss-6$0$0$Final$server$default$deploy$demo$portal$war"-ManagedBean-class_xxx$demoportal$controller$MemberRegistration_$$_WeldClientProxy' does not have the property 'member'.
           at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:108) [:2.0.3-]
           at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190) [:2.0.3-]
           at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178) [:2.0.3-]
           at javax.faces.component.UIOutput.getValue(UIOutput.java:164) [:2.0.3-]
           at com.sun.faces.renderkit.html_basic.HtmlBas