File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts dyna objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts dyna objects" Watch "Struts dyna objects" New topic

Struts dyna objects

Sri Anand
Ranch Hand

Joined: Mar 06, 2005
Posts: 392
I am using dynaforms, i have a customer form where i have one property as arraylist in dynaform

form-property name="activeInd" type="java.lang.String"
form-property name="assoc" type="java.util.ArrayList"

I am using display tags in the view everything works fine, but i have an add button in page where i can add a association, in one of java class i am updating the property like this when association is added by submitting request from add button

ArrayList currentAssocs = (ArrayList)customerForm.get("assoc");
String newAssocNumber = (String)customerForm.get("newAssocNumber");
Cust newAssocCust = Cust.readCustInfoFromDB(newAssocNumber, dataSession, transaction);

updating the form object with latest property with above code .later when i am trying to save(submit request from save button) I am trying to retrieve the arraylist i set but i dont get that back !!!
ArrayList currentAssocs = (ArrayList)customerForm.get("assoc");
if(currentAssocs!=null && currentAssocs.size()>0 ){
//save customer code here..

in struts config i have set the scope as request

<action name="newcustomerForm" path="/Permits/NewCustomer" input="permits.NewCustomer" parameter="action" scope="request" type="" validate="false">
<set-property property="secure" value="true"/>
<forward name="successGet" path="permits.NewCustomer"/>
<forward name="successUpdate" path="permits.NewCustomer"/> <forward name="successPost" path="permits.CustomerCreated"/>
<forward name="replay" path="permits.NewCustomer"/>

any Ideas!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you create a property in your form bean of type ArrayList, you can read from it, but you cannot write to it from a form submission. The Apache Commons BeanUtils used by Struts to convert request data to form bean properties cannot handle this conversion.

If you're not really intending to write to the ArrayList, just take it out of the form altogether and store it in request or session scope. Then you can read from it as needed, but it won't get wiped out when the form is submitted.
[ July 10, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Sri Anand
Ranch Hand

Joined: Mar 06, 2005
Posts: 392
Thank you so much for the reply, I got it working.
I agree. Here's the link:
subject: Struts dyna objects
It's not a secret anymore!