aspose file tools*
The moose likes Struts and the fly likes how to update data via list in Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to update data via list in Struts2" Watch "how to update data via list in Struts2" New topic
Author

how to update data via list in Struts2

namehas beentaken
Greenhorn

Joined: Dec 17, 2011
Posts: 2
Hi, everyone. I am new to Struts2, and I am trying to build a phone bill calcualte page. I use list to contain and successfully display them in the text fileds in jsp page. however, when I modify the data and submit, the action class does not catch anything and the list become null. Can anyone help me through it?
First, I declear a class PhoneMember which has my own attributes. (name, extra minutes cost ...) all of them are String type.
then, In action class I define the list and setter/getter
then I initial 5 elements and add them in the list. I also define a String parameter "total" for total cost.
later in jsp page, I use iterator
the initial value displayed successfully, but when I click the submit button, the phoneList in action class is null. all the data have been lost. But the "total" parameter receives the value;
Can any one helps me to solve this problem? I googled but can't find a solution. I also tried define another list in the action class and use that list name in the iterator. But neither lists get the data. Thanks very much
Nitin Surana
Ranch Hand

Joined: Jan 21, 2011
Posts: 129

This example exactly does what you want.

http://www.onlinexamples.com/showfullexample.action?idexamples=11&title=Iterator%20over%20an%20array/list%20of%20objects/beans

Advanced Example

http://www.onlinexamples.com/showfullexample.action?idexamples=10&title=Nested%20Iterators%20Example
namehas beentaken
Greenhorn

Joined: Dec 17, 2011
Posts: 2
Thanks for the help, Nitin. Finally I find the reason, it is necessary to define an empty constructor in bean file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to update data via list in Struts2