I figured this one out.  Man, what a landmine.  BTW, good suggestions from
all of you.

Here's what I did:

In my struts config I named the form property "cart".  See below

        <form-bean name="shoppingCartForm"
type="org.apache.struts.validator.DynaValidatorForm">
                <form-property name="cart"
type="com.je.common.ShoppingCartItem[]"/>        
        </form-bean>

Here's the gotcha:  You also have to name the "var" in the loop the exact
same name.  I should have said var="cart"  NOT var="item".  The code works
fine now.  The old code is below.  To fix just change "item" to "cart".  OH,
I also switched to <logic:iterate /> but that should not make any
difference.


<c:forEach var="item" items="${cartitems}">
        <tr>
                <td><c:out value="${item.id}" /></td>                
            <td><html:text name="item" indexed="true" property="unitPrice"
size="6" /></td>                
            <td><html:text name="item" indexed="true"
property="quantity"/></td>
            <%--<td><html:text name="total" value="" size="7"/></td>--%>
        </tr>
</c:forEach>


L8r all,  Man I wish the JBOSS site had as good a list as this one.  The
list has been a great help to me.

-----Original Message-----
From: Rick Reumann [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 27, 2004 12:23 AM
To: Struts Users Mailing List
Subject: Re: Dynamically sized form using dynavalidator

... and also, you're probably going to need to look into populating an empty
array or List called from your reset method. Pain in the butt, but there is
a lot in the archives about ways to handle it. For testing puprposes to
start with just give the form session scope which will avoid the problem
(but not necessarily the best thing in the world to do).

Rick Reumann wrote:

> I haven't tested this and it's late.. but your form property is "cart" 
> not item.. so if you are going to use JSTL (and not the nested tag 
> which is actually easier) it would be something like...
> 
> <c:forEach var="item" items="${cartitems}" varStatus="status">
> 
> <html:text property="cart[${status.index}].unitPrice" 
> value="${item.unitPrice}" /><br>
> ....
> 
> </c:forEach>
> 
> 
> Using the nested tag it would be:
> 
> <nested:iterate property="cartitems">
>      <nested:text property="unitPrice" />
>     <nested:text property="quantity" /> </nested:iterate>
> 
> 
> 
> Jim Kennedy wrote:
> 
>> Just to clarify something.  My expectation is that I can generate a 
>> form that can grow (row-wise) at runtime and change/modify values in 
>> that form.
>> The processing action could then retrieve the dynaform and the 
>> changed values would be saved back to whatever (array, collection 
>> list...)
>>
>>
>>
>>
>> -----Original Message-----
>> From: Jim Kennedy [mailto:[EMAIL PROTECTED] Sent: Wednesday, 
>> May 26, 2004 6:52 PM
>> To: 'Struts Users Mailing List'
>> Subject: Dynamically sized form using dynavalidator
>>
>> I have defined a form that will grow dynamically at runtime.  The 
>> problem I'm having is that the values entered in the form do not 
>> save.  The form pre-populated just fine.  I have an action that 
>> delivers the form and another action that processes the form.
>>
>> Here's the strutsconfig:
>>
>>         <form-bean name="shoppingCartForm"
>> type="org.apache.struts.validator.DynaValidatorForm">
>>             <form-property name="cart"
>> type="com.je.common.ShoppingCartItem[]"/>                </form-bean>
>>
>>
>>     <action        path="/propmgmt/viewcart"
>>     
>> type="com.je.struts.action.pm.ViewCartAction"
>>                 name="shoppingCartForm"
>>                 scope="session"
>>                 input=""
>>                 validate="false">
>>         <forward name="viewcart"
>> path="/tmpl_propmgmt2.jsp?pageleft=/propmgmt/leftmenu.jsp&amp;pagecen
>> ter=/pr
>>
>> opmgmt/viewcart.jsp&amp;pagetitle=home.title.key" />
>>     </action>
>>     
>>     <action        path="/propmgmt/checkout"
>>     
>> type="com.je.struts.action.pm.CheckOutAction"
>>                 name="shoppingCartForm"
>>                 scope="session"
>>                 input=""
>>                 validate="false">
>>         <forward name="checkoutform"
>> path="/tmpl_propmgmt2.jsp?pageleft=/propmgmt/leftmenu.jsp&amp;pagecen
>> ter=/pr
>>
>> opmgmt/checkout.jsp&amp;pagetitle=home.title.key" />
>>     </action>
>>
>>
>> =========================
>> Here's the JSP:
>>
>> <html:form action="/propmgmt/checkout.exe" method="post" scope="session">
>>     <table border="0" width="96%" class="listings">
>>         <tr><th>Shopping Cart Items</th><th>Price</th><th>Length of 
>> Ad</th><th>Item Total</th></tr>
>>         <c:forEach var="item" items="${cartitems}">
>>         <tr>
>>             <td><c:out value="${item.id}" /></td>                
>>             <td><html:text name="item" indexed="true" 
>> property="unitPrice"
>> size="6" /></td>                            <td><html:text name="item" 
>> indexed="true"
>> property="quantity"/></td>
>>             <%--<td><html:text name="total" value="" size="7"/></td>--%>
>>         </tr>
>>         </c:forEach>
>>     </table>
>>     
>>     <html:submit value="Proceed to Checkout-->"/> </html:form>
>>
>>
>> Like I said, the form prepopulates but when I enter new values I 
>> don't see them in the "checkout" action. The original entered values 
>> aren't getting overwritten.
>>
>> =======================================
>> Here's what the gen'd HTML looks like:
>>
>> <form name="shoppingCartForm" method="post"
>> action="/rentworx/propmgmt/checkout.exe">
>>     <table border="0" width="96%" class="listings">
>>         <tr><th>Shopping Cart Items</th><th>Price</th><th>Length of 
>> Ad</th><th>Item Total</th></tr>
>>         <tr>
>>             <td>2702wes8172</td>                            <td><input 
>> type="text" name="item[0].unitPrice" size="6"
>> value="9.95"></td>                            <td><input type="text" 
>> name="item[0].quantity" value="1"></td>
>>         </tr>
>>         <tr>
>>             <td>30712iv8164</td>                            <td><input 
>> type="text" name="item[1].unitPrice" size="6"
>> value="9.95"></td>                            <td><input type="text" 
>> name="item[1].quantity" value="1"></td>
>>         </tr>
>>         <tr>
>>             <td>665brya8155</td>                            <td><input 
>> type="text" name="item[2].unitPrice" size="6"
>> value="9.95"></td>                            <td><input type="text" 
>> name="item[2].quantity" value="1"></td>
>>         </tr>
>>     </table>
>>     <input type="submit" value="Proceed to Checkout-->"> </form>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
> 
> 


--
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to