ManyToMany Custom Look

View: New views
4 Messages — Rating Filter:   Alert me  

ManyToMany Custom Look

by ghachey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm very new to trails, and tapestry and hibernate too by that matter.  I'm evaluating trails but I have been blocked on this problem for a few days now.

I have a Society entity and a Person entity.  They are linked with a ManyToMany relationship like follows in Society.java:

@PropertyDescriptor(index = 14, searchable = false, summary = false)
@ManyToMany(
    targetEntity = vu.gov.departmentcooperative.Person.class,
    cascade = {CascadeType.PERSIST, CascadeType.MERGE}
)
@JoinTable(
    name = "society_person",
    joinColumns = @JoinColumn(name = "society_id"),
    inverseJoinColumns = @JoinColumn(name = "person_id")
)
public List<Person> getMembers() {
        return members;
}

public void setMembers(List<Person> newMembers) {
        this.members = newMembers;
}

The default look for this type of field when editing a Society is to use a palette component.  I changed this to include a TableObject of members (Person.java) belonging to that particular society like follows:

        <form jwcid="@trails:ObjectForm" model="ognl:model">
          <!-- Custom look (component) for members attribute -->
          <div id="members">
            <div id="left" style="float:left;" jwcid="members@Block">
              <li><label class="desc">Members</label>
                <table class="table contribTable" jwcid="@trails:ObjectTable"
                       rowsClass="ognl:beans.evenOdd.next"
                       instances="ognl:model.members"
classDescriptor="ognl:page.descriptorService.getClassDescriptor(classDescriptor.getPropertyDescriptor('members').elementType)"/>
              </li>
            </div>
            <div id="right" jwcid="@If" condition="ognl:classDescriptor.allowSave">
              <li>
                a class="newlink" href="#" jwcid="@trails:NewLink" type="ognl:@vu.gov.departmentcooperative.Person@class">Add a New Member
              </li>
            </div>
          </div>
        </form>

This obviously adds a new Person in the database but not specific to the Society I had opened for edit (or any Society at all).  In other words, it does not update the ManyToMany's JoinTable (society_person).

image for clarity.



Can someone help me out?

--
Ghislain Hachey

Re: ManyToMany Custom Look

by Alejandro Scandroli-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ghislain

Try this for your newlink

<li><a class="newlink" href="#" jwcid="@trails:NewLink"
type="ognl:@vu.gov.departmentcooperative.Person@class"
associationDescriptor="ognl:classDescriptor.getPropertyDescriptor('members')"
parent="ognl:model">Add a New Member</a></li>

This was meant to be used with child collections (aka: compositions)
but it may work in your case too.

Let me know if it works (or if it doens't).

Saludos.
Alejandro.

--
Alejandro Scandroli - http://weblog.amneris.es/
Amneris: We build process-driven web applications.
http://www.amneris.es


On Tue, Dec 16, 2008 at 7:00 AM, ghachey <ghachey@...> wrote:

>
> Hi,
>
> I'm very new to trails, and tapestry and hibernate too by that matter.  I'm
> evaluating trails but I have been blocked on this problem for a few days
> now.
>
> I have a Society entity and a Person entity.  They are linked with a
> ManyToMany relationship like follows in Society.java:
>
> @PropertyDescriptor(index = 14, searchable = false, summary = false)
> @ManyToMany(
>    targetEntity = vu.gov.departmentcooperative.Person.class,
>    cascade = {CascadeType.PERSIST, CascadeType.MERGE}
> )
> @JoinTable(
>    name = "society_person",
>    joinColumns = @JoinColumn(name = "society_id"),
>    inverseJoinColumns = @JoinColumn(name = "person_id")
> )
> public List<Person> getMembers() {
>        return members;
> }
>
> public void setMembers(List<Person> newMembers) {
>        this.members = newMembers;
> }
>
> The default look for this type of field when editing a Society is to use a
> palette component.  I changed this to include a TableObject of members
> (Person.java) belonging to that particular society like follows:
>
>        <form jwcid="@trails:ObjectForm" model="ognl:model">
>          <!-- Custom look (component) for members attribute -->
>          <div id="members">
>            <div id="left" style="float:left;" jwcid="members@Block">
>              <li><label class="desc">Members</label>
>                <table class="table contribTable" jwcid="@trails:ObjectTable"
>                       rowsClass="ognl:beans.evenOdd.next"
>                       instances="ognl:model.members"
> classDescriptor="ognl:page.descriptorService.getClassDescriptor(classDescriptor.getPropertyDescriptor('members').elementType)"/>
>              </li>
>            </div>
>            <div id="right" jwcid="@If" condition="ognl:classDescriptor.allowSave">
>              <li>
>                a class="newlink" href="#" jwcid="@trails:NewLink"
> type="ognl:@vu.gov.departmentcooperative.Person@class">Add a New Member
>              </li>
>            </div>
>          </div>
>        </form>
>
> This obviously adds a new Person in the database but not specific to the
> Society I had opened for edit (or any Society at all).  In other words, it
> does not update the ManyToMany's JoinTable (society_person).
>
> image for clarity.
>
> http://www.nabble.com/file/p21027777/pic.png
>
> Can someone help me out?
>
> --
> Ghislain Hachey
> --
> View this message in context: http://www.nabble.com/ManyToMany-Custom-Look-tp21027777p21027777.html
> Sent from the Trails - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: ManyToMany Custom Look

by ghachey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the VERY quick answer Alejandro,

Your suggestion did work (as long at parent object is persisted of course).

You probably won't be surprised however that once added, the member (Person object) cannot be deleted.  This is not a major problem in this particular case as I try to get the client to keep those records of members but flag them inactive when they leave the Society.  However, there would be case where the ability to delete those records would be desirable.  But now its my turn to struggle for the answer for some time

Thanks for your help and continue the good work

--
GH

Re: ManyToMany Custom Look

by Alejandro Scandroli-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Again

On Wed, Dec 17, 2008 at 1:47 AM, ghachey <ghachey@...> wrote:
>
> (...)
>
> Your suggestion did work (as long at parent object is persisted of course).

Of course, I forgot about that. The parent object must be persisted.
Add this to the newlink disabled="ognl:page.modelNew" so the link is
disabled if the object is not persisted.

> You probably won't be surprised however that once added, the member (Person
> object) cannot be deleted.  This is not a major problem in this particular
> case as I try to get the client to keep those records of members but flag
> them inactive when they leave the Society.  However, there would be case
> where the ability to delete those records would be desirable.  But now its
> my turn to struggle for the answer for some time :-)
>

Yeap, I know. Deletion is tricky. It's not easy to find a good
deletion strategy that fits every use case scenario.
In your case I would implement a method to take care of the "member"
deletion directly from the Person edit page and then add a "delete"
link to the ObjectTable.

Chears!
Alejandro

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email