Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DynaValidatorActionForm and java.util.ArrayList

 
Pallavi ch
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pallavi ch
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extension to the above.....
getting an exception Cannot create Iterator for CustomerBean

wat could be the cause??
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pallavi ch
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pallavi ch
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" />
 
Pallavi ch
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link. I've read this earlier but couldn't get any clue.
Here is my code :
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Pallavi ch
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic