You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Conrad <dr...@gmail.com> on 2007/04/20 02:19:38 UTC
[S1] Problem with nested objects?
Hello. I'm a bit of a newbie with Struts, and I'm running into some
problems with a form that has a nested java bean, which in turn has a
list of java beans. I had a version of this working when there wasn't
so much nesting, but something has gone awry, I think.
The form, PriceQuoteForm, has two "PriceLine" objects, and each of
these corresponds to a separate section on the html form. In each
section there is a list of Customers. I need to create some fields
with those Customers, and then get them back when the form is posted
back, naturally. The problem, I think, is the html ends up looking
like:
<input type="text" name="customer[0].cost" value="0.0" class="pq_currency">
Doesn't this need to be either "firstLob.customer[0].cost" or
"secondLob.customer[0].cost" in order for the form bean to get
populated when I post it back?
Here is the (stripped down) code I am using:
public class PriceQuoteForm extends BaseForm {
// ...
private PriceLine firstLob = new PriceLine();
private PriceLine secondLob = new PriceLine();
// ...
}
public class PriceLine {
// ...
private List customers;
// ...
}
The Customer beans are just dumb data holders, nothing to see there.
<html:form action="/PriceQuote.do">
<c:set var="form" value="${priceQuoteForm}"/>
<nested:nest property="firstLob">
<logic:notEqual name="priceQuoteForm" property="firstLob.lob"
value="-1">
<nested:iterate id="customer" property="customers"
type="com.wm.amp.domain.pricing.Container">
<div class="left" style="width: 150px;">
<nested:select indexed="true" name="customer"
property="customerId" styleClass="pq_select" style="width: 140px;">
<html:options collection="customers1"
property="key" labelProperty="value" />
</nested:select>
</div>
<div class="left" style="width: 80px;">
<nested:text indexed="true" name="customer"
property="quantity" styleClass="pq_currency" style="width: 50px;" />
</div>
<div class="left" style="width: 140px;">
<nested:select indexed="true" name="customer"
property="frequency" styleClass="pq_select" style="width: 140px;">
<html:options collection="frequencies"
property="key" labelProperty="value" />
</nested:select>
</div>
<div class="left" style="width: 50px;">
<span style="width: 20px;"></span>
<nested:checkbox indexed="true" name="customer"
property="compactor"/>
</div>
<div class="left" style="width: 100px;">
<nested:text indexed="true" name="customer"
property="cost" styleClass="pq_currency"/>
</div>
</nested:iterate>
</logic:notEqual>
</nested:nest>
</html:form>
(I was going to just include one of the fields, property="cost", but I
thought it would be better if I included more detail. This is just one
of the two sections of the form.)
I just switched over to using nested tags. I was hoping that it would
automatically add the nested:nest property at the beginning of the
field name, but no such luck. I also tried to use a logic:iterate tag
with id="firstLob.customer" and change all the tags inside the iterate
to have name="firstLob.customer", but that complains about the dot in
the name.
When I post back the form, the customers are not getting populated in
the form bean. I was able to make this work in a proof of concept (so
I thought) with just a few html-el:text tags, and the customers list
as part of them PriceQuoteForm bean rather than in a nested java bean.
I'm really tearing my hair out, now, and any help would be
tremendously appreciated. Thanks in advance,
David Conrad
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org