This may be childsplay for experienced Seam developers, but it took me quite some time to figure out how to use a ManyToMany mapping with a selectManyCheckbox that could be updated in both directions of the relationship. Here is an example Seam application which illustrates how to do this. It was built by starting off with seam-gen and then customising it; so all of the persistence heavy lifting is done by the EntityHome classes which the seam generated classes extend. I highly recommend reading Chapter 11. The Seam Application Framework from the seam reference documentation to get a better understanding of how to use EntityHome - none of the Seam books currently on the market really cover seam-gen in any depth.
The application has email Recipients who can belong to many Profiles. The UI allow you to add profiles to recipients and also to remove or edit recipients from profiles (the JSF EL extensions make this really slick).
Note that I've used a factory method for both Recipient and Profile so that I can reference the Recipient entity as "recipient" instead of "recipientHome.instance" and "profile" instead of "profileHome.instance":
and then:
The application has email Recipients who can belong to many Profiles. The UI allow you to add profiles to recipients and also to remove or edit recipients from profiles (the JSF EL extensions make this really slick).
Note that I've used a factory method for both Recipient and Profile so that I can reference the Recipient entity as "recipient" instead of "recipientHome.instance" and "profile" instead of "profileHome.instance":
@Factory("recipient")
public Recipient initRecipient() {
return getInstance();
}
and then:
<h:selectManyCheckbox value="#{recipient.profiles}">
<s:selectItems value="#{profileList}" var="profile" label="#{profile.name}" />
<s:convertEntity />
</h:selectManyCheckbox>
