aspose file tools*
The moose likes Struts and the fly likes DynaValidatorActionForm and java.util.ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DynaValidatorActionForm and java.util.ArrayList" Watch "DynaValidatorActionForm and java.util.ArrayList" New topic
Author

DynaValidatorActionForm and java.util.ArrayList

Lavanya ch
Ranch Hand

Joined: Dec 16, 2004
Posts: 75
hello all...
How can i use ArrayList property in DynaValidatorAtionForm?
<p>
I've a combo box , where multiple selection is allowed... say customers. I want to store those selected values to a ArrayList which is defined in struts-config.xml
I'm using this....

<html:select property="customers" multiple="true" size="3">
<html ptions collection="usersBean" property="users"/>
</html:select>

(usersBean is java bean , where i've the list of customers to populate)
and 'customers' is a proeprty in DynaValidatorActionForm.

<form-property name= "customers" type= "java.util.ArrayList"/>

when I add this property to my struts-config.xml , application is throwing exception...
<b>
SEVERE: Error creating form bean of class org.apache.struts.validator.DynaValidatorActionForm
java.lang.IllegalArgumentException: Invalid property name 'customers'
</b>
I'm not able to figure out the cause...
what could be the problem?

or any other way to accomlish this task??

Thanks in advance
Lavanya ch
Ranch Hand

Joined: Dec 16, 2004
Posts: 75
Extension to the above.....
getting an exception Cannot create Iterator for CustomerBean

wat could be the cause??
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When you allow multiple values in an <html:select> tag, struts does not support using an ArrayList or any other collection to hold the value. You must use type java.lang.String[]. Otherwise, you will get this error when Struts tries to poplulate the form bean.


Merrill
Consultant, Sima Solutions
Lavanya ch
Ranch Hand

Joined: Dec 16, 2004
Posts: 75
I've tried with property String[].
but getting the same exception Cannot create iterator for Customers .
is this exception really related to bean populaion?
becoz we have exclusice exception for that... beanUtils.populate exception.
Lavanya ch
Ranch Hand

Joined: Dec 16, 2004
Posts: 75
sorry.The exact exception is... Cannot create iterator for usersBean@a2bd15 . i was cinfused in bean names.
I've a basic doubt here... this html ption collection is supported by which version of struts?
and moreover saving it to dynaform using String[] is possible??
do i need any specail jar file to accomlish this?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The <htmlptions> tag is supported by all versions of Struts.

It appears you may have used it incorrectly. See This link for instructions on how to use it.

If users is a property in usersBean that contains a collection of Strings that are to be used as the options, the proper usage of the tag would be:

<options name="userBean" property="users" />

If the users property contains a collection of ojbects (for example, a User object with a name and id property) Then you must specify which property is to be used for the value and which for the label. In this case, the <htmlptionsCollection> tag is more appropriate. It would look something like this:

<htmlptionsCollection name="userBean" property="users" label="name" value="id" />
Lavanya ch
Ranch Hand

Joined: Dec 16, 2004
Posts: 75
Thanks for the link. I've read this earlier but couldn't get any clue.
Here is my code :
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The <htmlptions> tag is still coded incorrectly.

Given what you have shown me of your bean, the correct entry should be:

<htmlptions name="usersBean" property="users" />

P.S. It is against standard java practice to begin a class name with a lower case character. I'd suggest you change the usersBean class name to UsersBean.
[ April 18, 2006: Message edited by: Merrill Higginson ]
Lavanya ch
Ranch Hand

Joined: Dec 16, 2004
Posts: 75
Thanks for the help.
I've left that <html ptions collection > tag and used
<html ptions name>
it's working fine. Though i'm getting Conversion Exception after submit, I think i can handle that.
And... the Naming convention for java class is my mistake.
anywyas...thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DynaValidatorActionForm and java.util.ArrayList