Dave,

Thanks for the tip, it worked perfectly! To recap, I changed the addresses
mapping....

    /** persistent field */
    @OneToMany(mappedBy="customer",
targetEntity=com.inftropy.plus.account.Customer.model.Address.class, cascade
= { CascadeType.ALL}, fetch=FetchType.EAGER)
    @IndexedEmbedded
    @MapKey(name="id")
    private Map<java.lang.Long, Address> addresses;

... and the jsp...

        <table>
          <tr>
            <td>
              <s:text name="addressIdTitle"/>
            </td>
            <s:iterator value="#attr.customer.addresses"
status="custAddressStatus">
            <td>
              <s:textfield name="addresses[%{key}].id" value="%{value.id}"/>
            </td>
            </s:iterator>
          </tr>
          <tr>
            <td>
              <s:text name="addressCodeTitle"/>
            </td>
            <s:iterator value="#attr.customer.addresses"
status="custAddressStatus">
            <td>
              <s:textfield name="addresses[%{key}].code"
value="%{value.code}"/>
            </td>
            </s:iterator>
          </tr>
        </table>


Best,
Ryan


On Tue, Oct 12, 2010 at 1:26 PM, Dave Newton <davelnew...@gmail.com> wrote:

> I don't know about sets; personally I'd use a map so you actually have a
> way
> to access them by something meaningful, like an ID. Then you use map-based
> property field names (it's [] or (), with the key inside, I forget which
> off
> the top of my head). I think () is for indexed, so I'd aim for [] first.
>
> Dave
>
> On Tue, Oct 12, 2010 at 2:21 PM, Ryan Beckes <rbec...@gmail.com> wrote:
>
> > Hello,
> >
> > I'm using an action which implements the ModelDriven interface where my
> > model is a hibernate POJO (e.g. Customer). In this Customer I have a
> > OneToMany relationship with another hibernate POJO (e.g. Address)...
> >
> >    /** persistent field */
> >    @OneToMany(mappedBy="customer",
> > targetEntity=com.inftropy.plus.account.Customer.model.Address.class,
> > cascade
> > = { CascadeType.ALL}, fetch=FetchType.EAGER)
> >    @IndexedEmbedded
> >    private Set<Address> addresses;
> >
> > ... I'm trying to create a form that allows the setting for multiple
> > addresses for the current customer. For example, say my address has two
> > fields (id and name) and I want to set two addresses for a certain
> > Customer....
> >
> > BEGIN jsp
> > <s:iterator value="model" status="customerStatus" id="customer">
> >        <table>
> >          <tr>
> >            <td>
> >              <s:text name="addressIdTitle"/>
> >            </td>
> >            <s:iterator value="#attr.customer.addresses"
> > status="custAddressStatus">
> >            <td>
> >              <s:textfield name="addresses.id" value="%{id}"/>
> >            </td>
> >            </s:iterator>
> >          </tr>
> >          <tr>
> >            <td>
> >              <s:text name="addressCodeTitle"/>
> >            </td>
> >            <s:iterator value="#attr.customer.addresses"
> > status="custAddressStatus">
> >            <td>
> >              <s:textfield name="addresses.code" value="%{code}"/>
> >            </td>
> >            </s:iterator>
> >          </tr>
> > </s:iterator>
> > END jsp
> >
> > BEGIN resulting html
> >
> >        <table>
> >          <tr>
> >            <td>
> >              addressIdTitle
> >            </td>
> >
> >
> >            <td>
> >              <input type="text" name="addresses.id" value="2"
> > id="Customer_update_addresses_id"/>
> >            </td>
> >
> >            <td>
> >              <input type="text" name="addresses.id" value="1"
> > id="Customer_update_addresses_id"/>
> >            </td>
> >
> >          </tr>
> >          <tr>
> >            <td>
> >
> >              addressCodeTitle
> >            </td>
> >
> >            <td>
> >              <input type="text" name="addresses.code" value="SHIPTO"
> > id="Customer_update_addresses_code"/>
> >            </td>
> >
> >            <td>
> >              <input type="text" name="addresses.code" value="BILLTO"
> > id="Customer_update_addresses_code"/>
> >            </td>
> >          </tr>
> >       </table>
> > END resulting html
> >
> > ... Is there a convention I can use (in this case I tried
> > addresses.<field>, which didn't work) so that the fields I set
> > correspond to the associated Address object for the current model?
> >
> > Thanks,
> > Ryan
> >
>

Reply via email to