File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How I can edit 'java.util.Set' DynaValidatorForm form-property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How I can edit Watch "How I can edit New topic
Author

How I can edit 'java.util.Set' DynaValidatorForm form-property

Slava Lovkiy
Greenhorn

Joined: Aug 17, 2005
Posts: 29
I have the following form description in struts-config.xml:

How can I specify type for element in set so that struts nows which object to create.
Is it possible to post input files as indexed properties?
How I can update such property from jsp?
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
Set extends Collection. indexed properties works with Collection. you make the deduction. instructions: http://struts.apache.org/faqs/indexedprops.html


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Slava Lovkiy
Greenhorn

Joined: Aug 17, 2005
Posts: 29
Suppose, I have an empty form, with button 'add', which runs the javascript function. This function renders input fields, and user now is able to enter some data.



Once user submit data, I need certain java.util.Set populated with objects of type User, which has 2 properties 'name' and 'email'
Number of elements in Collection may vary, depending on how much rows were created on page.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
once again, indexed properties is the answer. in your case, it's the generated HTML codes when you use the html:input indexed="true".

your javascript needs to generate the proper name of each of your input fields each time they are added, e.g <input name="name[0]" value=""/> <input name="email[0]" value=""/> <br /> <input name="name[1]" value=""/> <input name="email[1]" value=""/>
Swamy Nathan
Ranch Hand

Joined: May 16, 2004
Posts: 187
Should it not be as folows?
<input name="user[0].name" value=""/> <input name="user[0].email" value=""/> <br /> <input name="user[1].name" value=""/> <input name="user[1].email" value=""/>
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
swami, absolutely! thanks for the correction.
Slava Lovkiy
Greenhorn

Joined: Aug 17, 2005
Posts: 29
THanks guys for your replys
In fact, when i use the naming convention for index properties, indeed it will populate the list of objects if IT DOES HAVE certain element placeholer created in the ArrayList or Object[]. But if my dyna form was initialized with empty list or empty array, than BeanUtils.populate() fails to populate the object in collection with specified index - got Exception 'ArrayIndexOutOfBound'. BeanUtils.populate() doesn't create missing elements in array automaticly - it should be there prior to populate with values from the request.

I can specify a size of array to some very big number, but this would solve the problem of dynamic resizing of list (or array of objects).
Moreover, if input form is used for initial list populatation, there is no information about which object to instantiate to store the vaues from request, if form property is the ArrayList or Set - anything can be stored in this list, not certain type of instance (is it can be done in case of array of object, where type of element is described in array declaration).

Any suggestions to all this above?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How I can edit 'java.util.Set' DynaValidatorForm form-property