5 Replies Latest reply on Jan 10, 2007 4:46 AM by patrick.antivackis

    Seam Application Framework : association management

    patrick.antivackis

      I do not really understand the association management as explained in Chapter 14 of SEAM 1.1GA documentation. Is there a place where to find the complete example described in this chapter ?
      If no, does someone know how to use the concept of @DataModel and @DataModelSelector with the Framework.

      Thank you

        • 1. Re: Seam Application Framework : association management

          Here's one way to get started, I suppose. In general, I think you'd want to combine an EntityQuery with an EntityHome though, and not mess about with manually managing it like this.

          @Name("fooList")
          public class FooList
           extends EntityQuery
          {
           @DataModelSelection
           Foo selectedFoo;
          
           @DataModel
           public List getAllFoo() {
           return super.getResultList();
           }
          
           public void actOnSelected() {
           .... use selectedFoo
           }
          }
          
          


          • 2. Re: Seam Application Framework : association management
            patrick.antivackis

            Hello Norman, thank for your time and help, so to make it clearer just let's stick to the example in chapter 14. We have the person class :

            @Entity
            public class Person {
             @Id private Long id;
             private String firstName;
             private String lastName;
             private Country nationality;
            
             //getters and setters...
            }
            


            The personHome class :
            <h1>
             <h:outputText rendered="#{!personHome.managed}" value="Create Person"/>
             <h:outputText rendered="#{personHome.managed}" value="Edit Person"/>
            </h1>
            <h:form>
             <div>First name: <h:inputText value="#{person.firstName}"/></div>
             <div>Last name: <h:inputText value="#{person.lastName}"/></div>
             <div>
             <h:commandButton value="Create Person" action="#{personHome.persist}" rendered="#{!personHome.managed}"/>
             <h:commandButton value="Update Person" action="#{personHome.update}" rendered="#{personHome.managed}"/>
             <h:commandButton value="Delete Person" action="#{personHome.remove}" rendered="#{personHome.managed}"/>
             </div>
            </h:form>
            
            @Name("personHome")
            public class PersonHome extends EntityHome<Person> {
            
             @In Country country;
            
             @Factory("person")
             public Person initPerson() { return getInstance(); }
            
             public void migrate()
             {
             getInstance().setCountry(country);
             update();
             }
            }
            


            A country class, let's say :
            @Entity
            public class Country {
             @Id private Long id;
             private String countryName;
            
             //getters and setters...
            }
            

            The database is populated with countries.

            An entity query for the countries ;
            <framework:entity-query name="countries" ejbql="select c from Country c"/>
            


            The editPerson as defined in the example :
            <h1>
             <h:outputText rendered="#{!personHome.managed}" value="Create Person"/>
             <h:outputText rendered="#{personHome.managed}" value="Edit Person"/>
            </h1>
            <h:form>
             <div>First name: <h:inputText value="#{person.firstName}"/></div>
             <div>Last name: <h:inputText value="#{person.lastName}"/></div>
             <div>
             <h:commandButton value="Create Person" action="#{personHome.persist}" rendered="#{!personHome.managed}"/>
             <h:commandButton value="Update Person" action="#{personHome.update}" rendered="#{personHome.managed}"/>
             <h:commandButton value="Delete Person" action="#{personHome.remove}" rendered="#{personHome.managed}"/>
             </div>
            </h:form>
            


            My question is : Is there an easy way to add a country selector in the editPerson page ?

            Thank you



            • 3. Re: Seam Application Framework : association management

              In fact there is a very convenient way to realize this. by using the http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamSelectItemsNewDesign component.

              <si:selectItems value="#{countries.resultList}" var="country" label="#{country.countryName}" noSelectionLabel="Select One..."/>
              



              :)

              ps: I guess I don't know how to use the url formatter correctly...it always prints the url instead of the text I entered in the tag :/

              • 4. Re: Seam Application Framework : association management

                I forgot..., u probably wanna surround the si:selectitems with a h:selectone or smth similar:

                <h:selectOneMenu value="#{person.country}" >
                <si:selectItems value="#{countries.resultList}" var="country" label="#{country.countryName}" noSelectionLabel="Select One..."/>
                </h:selectOneMenu>
                

                :P

                • 5. Re: Seam Application Framework : association management
                  patrick.antivackis

                  Thanks Atzbert, your link to the selectItems was great, have example using the framewrok inside. Just what i was looking for