0 Replies Latest reply on Feb 28, 2007 12:58 PM by Adam Just

    Nested conversation/seam object hidden by parent conversatio

    Adam Just Newbie

      I have the following simple scenario (a modification of the booking example): An aggregate entity, Business, with OneToMany relationships with Address, Contact, and Opportunity. For managing Business, I have a Conversation scoped Stateful Session Bean/Seam Component, that also models an Address, a Contact, and an Opportunity (so that one may be selected and acted upon).

      Another Stateful Session Bean is used for each of CreateAddress, CreateContact, and CreateOpportunity. No matter what combination of annotations/code I use, the Seam Entity objects already visible in the parent conversation are found, and injected into the CreateXYZ Converstation, and the form is filled in with the existing values.

      In the CreateXYZ form, specifically selecting form values not associated with the parent's Object, but instead with the CreateXYZ Object/Action leads to a "Error model data update." Using form values directly from the XYZ Entity leads Seam to inject the existing Entity from the Parent's conversation.

      Attempts to reassign the @In XYZ object within the CreateXYZ Stateful Session Seam Component lead to a derived object not being properly created as a member of Parent (Business') Collection(s).

      In the listings below, I have attempted to omit extraneous information. Consequently, please forgive omissions not related to the issue at hand.

      Thank You, Adam

      @Entity
      @Name("business")
      public class Business implements Serializable {
      
       private long id;
      
       private Collection<Address> addresses = new ArrayList<Address>();
      
       private Collection<Contact> contacts = new ArrayList<Contact>();
      
       private Collection<Opportunity> opportunities = new ArrayList<Opportunity>();
      
       public Business() {
      
       }
      
       @Id @GeneratedValue
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      
      
       @OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.LAZY)
       public Collection<Address> getAddresses() {
       return addresses;
       }
      
       public void setAddresses(Collection<Address> addresses) {
       this.addresses = addresses;
       }
      
       @OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.LAZY)
       public Collection<Contact> getContacts() {
       return contacts;
       }
      
       public void setContacts(Collection<Contact> contacts) {
       this.contacts = contacts;
       }
       @OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.LAZY)
       public Collection<Opportunity> getOpportunities() {
       return opportunities;
       }
      
       public void setOpportunities(Collection<Opportunity> opportunities) {
       this.opportunities = opportunities;
       }
      
      
       @Override
       public String toString() {
       return "Business(" + id + ")";
       }
      
      }
      
      


      @Entity
      @Name("address")
      public class Address implements Serializable {
       /**
       *
       */
       private static final long serialVersionUID = 1L;
      
       private long id;
      
      
       /**
       * The public no-argument constructor for AddressBean.
       */
       public Address() {
       //
       }
      
       @Id @GeneratedValue
       public long getId() {
       return id;
       }
      
       public void setId(long id) {
       this.id = id;
       }
      
      
      }
      


      @Stateful
      @Name("businessManaging")
      @LoggedIn
      public class BusinessManagingAction implements BusinessManaging {
      
       @PersistenceContext(type=EXTENDED)
       private EntityManager em;
      
       @In(required=false) @Out
       private Business business;
      
       @In(required=false) @Out(required=false)
       private Contact contact;
      
       @In(required=false) @Out(required=false)
       private Address address;
      
       @In(required=false) @Out(required=false)
       private Opportunity opportunity;
      
       @In
       private FacesMessages facesMessages;
      
       @Logger
       private Log log;
      
       @Begin(join=true)
       public String selectBusiness(Business selectedBusiness) {
       log.info("Selected Business: #{selectedBusiness.id}");
       business = em.merge(selectedBusiness);
       return "business";
       }
      
       public String updateBusiness(Business modifiedBusiness) {
       business = em.merge(modifiedBusiness);
       return "business";
       }
      
       public String selectContact(Contact contact) {
       log.info("Selected Contact: #{contact.id}");
       this.contact = contact;
       return "editcontact";
       }
      
       public String updateContact() {
       log.info("Updating: #{contact.id}");
       em.merge(contact);
       return "business";
       }
      
       public String selectAddress(Address address) {
       log.info("Selected Address: #{address.id}");
       this.address = address;
       return "editaddress";
       }
      
       public String updateAddress() {
       log.info("Updating: #{address.id}");
       em.merge(address);
       return "business";
       }
      
       public String selectOpportunity(Opportunity opportunity) {
       log.info("Selected Opportunity: #{opportunity.id}");
       this.opportunity = opportunity;
       return "editopportunity";
       }
      
       public String updateOpportunity() {
       log.info("Updating: #{opportunity.id}");
       em.merge(opportunity);
       return "business";
       }
      
       public String addContact() {
       business.addContact(contact);
       return "business";
       }
      
       public String removeContact(Contact contact) {
       business.removeContact(contact);
       return "business";
       }
      
       public String addAddress() {
       business.addAddress(address);
       return "business";
       }
      
       public String removeAddress(Address address) {
       business.removeAddress(address);
       return "business";
       }
      
       public String addOpportunity() {
       business.addOpportunity(opportunity);
       return "business";
       }
      
       public String removeOpportunity(Opportunity opportunity) {
       business.removeOpportunity(opportunity);
       return "business";
       }
      
       @End
       public String cancel() {
       return "businesses";
       }
      
       @Destroy @Remove
       public void destroy() {
      
       }
      
      }
      


      @Stateful
      @Scope(CONVERSATION)
      @Name("createAddress")
      public class CreateAddressAction implements CreateAddress {
      
       @In(required=false) @Out
       private Business business;
      
       @In(required=false)
       private Address a = new Address();
      
       @PersistenceContext(type=EXTENDED)
       private EntityManager em;
      
       @In
       private FacesMessages facesMessages;
      
       @Logger
       private Log log;
      
       @Begin(nested=true)
       public String selectBusiness(Business selectedBusiness) {
       log.info("a == null : " + (a==null));
       business = em.merge(selectedBusiness);
       a = new Address();
       return "createaddress";
       }
      
      
       @End
       public String createAddress() {
       log.info("A looks like #{a}");
       business.addAddress(a);
       return "business";
       }
      
       @Destroy @Remove
       public void destroy() {}
      }