Have you considered using HashMaps or ArrayLists in your forms. BeanUtils supports 
this kind of thing and therefor so does struts. some thing like...

// Load object from the database in init action.
HashMap users = new HashMap();

//for each user load key into map.
users.put(dbUser.getId, dbUser);

//Place users into Form
form.setUsers(users);


<!--In jsp-->
<html:form action=someAction />

<logic:iterate id="user" name="someForm" property="users" >
<bean:write name="someForm" property="user.userId" />

<!-- This is where it gets harry —>
<html:text name="someForm" property="<%="user(\""+ user.getUserId +"\" ).active"%>" />


</logic:itereate>

In the post-accepting action the form.getUsers will be populated appropriately. We 
have used this approach with struts 1.0.2 to good effect. There are some drawbacks 
though. JavaScript doesn't like "." in form element names. This can be overcome, 
though I forgot how we did it. And this does kinda rely on session. If I thought about 
it a little longer I could probably fix that too.

Will Etson
>>> "Galbreath, Mark" <[EMAIL PROTECTED]> 10/04/02 11:01AM >>> 
Yes, you can be sure, because form elements are actually an array, and one 
element will follow another. 

Mark 

-----Original Message----- 
From: Mark Silva [ mailto:[EMAIL PROTECTED]] 
Sent: Friday, October 04, 2002 1:59 PM 
To: Struts Users Mailing List 
Subject: RE: Design Problem: Multiple Object Update 


Pavel, 

Can we assume that the parameters will be sent in the right order? I have 
always assumed that this was something that could not be guarenteed with a 
form submission? i could be wrong about this point. 

thanks, 
mark 


-----Original Message----- 
From: Pavel Kolesnikov [ mailto:[EMAIL PROTECTED]] 
Sent: Friday, October 04, 2002 10:57 AM 
To: Struts Users Mailing List 
Subject: RE: Design Problem: Multiple Object Update 


On Fri, 4 Oct 2002, Mark Silva wrote: 

> so if you had a bunch of parameters like so 
> 
> category=XYZ&key=123&category=ABC&key=256&category=AAA 
> 
> how does struts correspond the category to the key? 

They don't. You have to go manually through all the arrays 
(getCategory, getKey etc) and suppose all the values are 
set in the appropriate order. 

So you can do somthing like: 

for (i = 0; i < key.size && i < category.size; i++) { 
System.out.println ("key: " + key[i] 
+ ", category: " + category[i]); 
} 

I think it's nicer than parsing stuff like 
123_category=XYZ&124_category=ABC&129_category=AAA&123_color ... 
;) 

Pavel 




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


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

Reply via email to