Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Struts2 Save and Get updated List?

 
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;
}
}
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!