3 Replies Latest reply on Apr 20, 2007 2:45 PM by Joel Thompson

    many-to-many (dynamically shown) on same JSF page

    Joel Thompson Newbie

      Hello,
      Lets say i have a user that has a M-M relationship with preferences.
      The preferences should show up as "Checkboxes" or "RadioButtons" on the screen. I create the POJO user class with a Set of preferences annotated with Many-to-Many. The list of available preferences (from the system) are database driven - So I can't hard code the JSF page with the components and conversely I can't have the backing bean with the data controls there.

      Question: if I want one JSF page with User attributes and this list of preferences to show up underneath the user info, and I want to have one SAVE button that will save the entire graph of objects, what is the best way to do this? I know I can create a backing bean (w/ action handler on the save button) and loop through the parameters and setup the preference objects that way, but I was hoping that there is some sort of component or pattern that I can take advantage of in SEAM or JSF.

      Thanks!

        • 1. Re: many-to-many (dynamically shown) on same JSF page
          Pete Muir Master

          Post the entities involved in the relationship you describe

          • 2. Re: many-to-many (dynamically shown) on same JSF page
            Joel Thompson Newbie

            Hello Petemuir - thanks for replying - I just gave these as examples of a many-to-many relationship. I don't have them to post, but besides it is a bit irrelevant since the question is really about what is the best way to manage dynamically generated jsf-seam components that have a master-detail relationship; where we want to have the "details" editable/saveable along with the master from the same screen.

            • 3. Re: many-to-many (dynamically shown) on same JSF page
              Joel Thompson Newbie

              I'd like some help with how the JSF dataTable
              and single/multi selects are setup and how to setup
              the SLSB to handle the SAVE on this scenario.

              Here are the objects and tables roughed in .

              public class Person
              {
              String FNAME="";
              List preferences=null;
              @ManyToMany
              @JoinTable (name="Person_SysPref"
              joinColumns=@JoinColumn(name="PERSON_ID"),
              inverseJoinColumns=@JoinColumn(name="PREF_ID"))
              public List getPreferences()
              {
              return preferences;
              }
              ... w/ getters and setters
              }

              public class Pref
              {
              String name="";
              String selected="";
              String group="";
              ... w/ getters and setters
              }

              ~ tables ~

              create table Person
              (
              PERSON_ID number primary key, -- surrogate generated key by person_seq sequence
              FNAME varchar2(30)
              );

              create table SysPref
              (
              SYSPREF_ID number primary key, -- surrogate generated key by SysPref_seq sequence
              NAME varchar2(30),
              GRP varchar2(20)
              );

              create table Person_SysPref
              (
              PERSON_SYSPREF_ID number primary key,
              SYSPREF_ID number, --fk to SysPref
              PERSON_ID number -- fk to Person table
              selected char(1)
              );

              The front end :
              a create form to input the Person.FNAME
              and on same form a list of Pref options (derived directly from the SysPrefs table).

              Once I hit the "SAVE" button (it is bound to SLSB, not shown here), the Person will be CREATED, and then I loop though all the "preferences" store all of them in the Person_SysPref table, with selected flag for that Person.

              The concept of "injecting" the Person object into a SLSB is clear from samples,but how do I get the list of Preferences (available from the SysPrefs)? And then once I have Person object existing, how do I associate this list of Prefs directly with the Person.preferences instead of the SysPrefs?

              One last thing - on the UI, I'd like to be able to group the preferences by the GRP value - for example,

              colors: (single select radio buttons)
              red
              green
              blue
              size: (single select radio buttons)
              small
              med
              lg
              Favorite Sports: (multiselect check boxes)
              hiking
              biking
              running

              If you can give me some general direction or even code examples. on this, I'd really appreciate it.


              Thanks again!