• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 Save and Get updated List?

 
Prem Hans
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I am trying an example in Struts 2 where I am fetching Username and Address from database and populating every Row using Users Object in List and Iterating that list in jsp using s:iterator
<s:iterator id="list" value="list">
<tr>
<td>
<s:textfield name="userName" />
</td>
<td>
<s:textfield name="address" />
</td>
</tr>
</s:iterator>
Further, I want to edit and save this List from same Jsp. When I click Save whats the best way to fetch this List in my Save method? At present I am using request.getParameterValues("userName"). this gives me my updated list. Any other way (i mean in struts2 best practice) to get the updated List Back?
 
Prem Hans
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I got this one! Now I am using name as users[%{#stat.index}]... this has solved my problem.
<s:iterator id="users" value="users" status="stat">
<s:textfield id="users" name="users[%{#stat.index}].userName" readonly="true"/>
<s:textfield id="users" name="users[%{#stat.index}].address" readonly="true"/>
</s:iterator>
but when accessing these generated fields is a prob via javascript to make readonly=false. So here's what i did

var fieldsUsr= document.getElementsByTagName('input');
for(a=0;a<fieldsUsr.length;a++){
if(fieldsUsr[a].type=='text' && fieldsUsr[a].id=='users'){
fieldsUsr[a].readOnly=false;
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic