3 Replies Latest reply on Apr 25, 2007 2:07 PM by petedog

    Injection Problem

    petedog

      I'm constructing a form for a customer and in this form I have multiple people (ie, "First Name", "Last Name", etc) as points of contact. Basically, I have 2 different Contact instances on the Action that I want to connect the form to and I'm not getting it to work. I'm trying to use the @In(value="contact"), @In("contact"), etc and it still keeps complaining, displaying this when doing seam validation: "value could not be converted to the expected type". If someone knows of of a way to make this work, I would appreciate it.

      Thanks,

      Peter

      Here's the code for the entity and Action:


      
      @Entity
      @Name("contact")
      @Table(name = "CONTACT")
      
      public class Contact implements java.io.Serializable {
      
       private Long id;
      
       private String firstName;
      
       ......
      }
      
      
      
      @Stateful
      @Scope(SESSION)
      @Name("customerFormAction")
      public class CustomerFormAction implements ICustomerFormAction, Serializable {
      
       private static final long serialVersionUID = 1L;
      
       @Logger private Log log;
      
      
       @In(value="contact")
       Contact contact1;
      
       @In(value="contact")
       Contact contact2;
      
       ........
      }
      



      Here is also a bit of code of the xhtml page that I'm trying to connect to contact1 and contact2 entities on the Action:

      
       ...............
      
       Contact 1 First: <h:inputText value="#{contact1.firstName}"/>
       Contact 1 Last: <h:inputText value="#{contact1.lastName}"/>
      
       Contact 2 First:<h:inputText value="#{contact2.firstName}"/>
       Contact 2 First:<h:inputText value="#{contact2.lastName}"/>
      
       ...........
      
      
      


        • 1. Re: Injection Problem
          fernando_jmt

           

          @Entity
          @Name("contact")
          @Role(name="contact1")
          @Table(name = "CONTACT")
          
          public class Contact implements java.io.Serializable {
          
           private Long id;
          
           private String firstName;
          
           ......
          }
          





          @Stateful
          @Scope(SESSION)
          @Name("customerFormAction")
          public class CustomerFormAction implements ICustomerFormAction, Serializable {
          
           private static final long serialVersionUID = 1L;
          
           @Logger private Log log;
          
          
           @In
           Contact contact;
          
           @In
           Contact contact1;
          
           ........
          }
          
          





          ...............
          
           Contact 1 First: <h:inputText value="#{contact.firstName}"/>
           Contact 1 Last: <h:inputText value="#{contact.lastName}"/>
          
           Contact 2 First:<h:inputText value="#{contact1.firstName}"/>
           Contact 2 First:<h:inputText value="#{contact1.lastName}"/>
          
           ...........
          
          


          • 2. Re: Injection Problem
            sjmenden

            What does contact1 and contact2 refer to? Without seeing the rest of your code it looks like you need to set up roles for the entity:

            @Entity
            @Name("contact")
            @Table(name = "CONTACT")
            @Roles(
             { @Role(name="contact1", scope=EVENT)
             @Role(name="contact2", scope=EVENT)}
            )
            public class Contact {
             ...
            }
            



            Alternatively, the method I prefer, you could create a ContactHome which extends EntityHome where you could hold references to Contact contact1, Contact contact2 with the getters and setters. then reference in the form through contactHome.contact1.firstname ect...

            • 3. Re: Injection Problem
              petedog

              Thanks! By adding the @Roles/@Role annotation to the entity it now works.

              /P