Announcement Announcement Module
Collapse
No announcement yet.
binding many-to-many relationships Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • binding many-to-many relationships

    I hope I chose a good title for this.

    I have a Hibernate backed many-to-many relationship using a join table.

    Code:
        @ManyToMany(
            targetEntity=package.path.CausesOfDisc.class,
            cascade={CascadeType.MERGE}
        )
        @JoinTable(
            table=@Table(name="investigation_causes_of_disc"),
            joinColumns={@JoinColumn(name="investigation_id")},
            inverseJoinColumns={@JoinColumn(name="causes_of_disc_id")}
        )
        public List<CausesOfDisc> getCausesOfDisc() {
            return causesOfDisc;
        }
    So... my causes_of_disc table contains 17 rows with the different possibilities and each Investigation object can have 0 to 17 CausesOfDisc objects in a List. Reading and displaying of the CausesOfDisc List works fine with Spring... this part is easy.

    My question is what the easiest way is to bind to checkboxes in my html form. I will have at this point 17 checkboxes for each of the possibilities. What I'm not sure of, is what the easiest way is to make these checkboxes bind to my Command object in a way where I don't have to do multiple loops through my persisted collection vs what comes across in the Request and remove those that did not come across in the Request and add those that did not already exist in the persisted collection.

    Just in case this makes more since... if of the 17, I already have #s 1, 2, & 3 (pk ids of CausesOfDisc) of 17 persisted for my Investigation. I now want to add #8 and remove #2 (check #7 and uncheck #2)... I would like to know if I could do something in the binding process so that it knows to take whatever comes across from the Request which will be 1, 3 & 8 and automagically remove #2 and add #8. But I'm not sure this is possible using the default mechanisms. So if not possible... what do you'all suggest using to make this as painless as possible?


    I really hope I'm making since. Please let me know if I can clarify anything.


    Thanks,
    Steve
Working...
X