Solved

struts iterate not updating, action doesn't load my changed values

Posted on 2012-03-17
8
442 Views
Last Modified: 2012-08-02
I've looked at other examples on this site, but none seem to do the trick for me...

I'm able to display the data in my form just fine, whether I use the iterate tag or the form alone.  When I use the iterate tag and change a value in the jsp, the action doesn't recognize the new value in my property.

struts-config:
    <form-beans>
        <form-bean name="EditUpdateFrm" type="com.awa.test.strutsactionform.EditUpdateForm" />
    </form-beans>

<action path="/TestUpdateSubmit"  
	type="com.awa.test.strutsaction.TestUpdateSubmitAction" 
	scope="session"  
	name="EditUpdateFrm" >
</action> 

Form:
public class EditUpdateForm extends ActionForm{
	private EditRecordObject[] editRecordObjects = new EditRecordObject[200];
	public EditRecordObject getEditRecordObjects(int i){
		return editRecordObjects[i];
	}
	public EditRecordObject[] getEditRecordObjects(){
		return editRecordObjects;
	}
	public void setEditRecordObjects(int i, EditRecordObject val){
		editRecordObjects[i] = val;
	}
	public void setEditRecordObjects(EditRecordObject[] val){
		editRecordObjects = val;
	}
}


JSP:
<html:form action="TestUpdateSubmit.do" type="com.awa.test.strutsactionform.EditUpdateForm" >    
<INPUT TYPE="Submit" class="SmallTextBlack" VALUE="UPDATE" NAME="Button" />
    <nested:iterate id="form1" scope="session" name="EditUpdateFrm" property="editRecordObjects" >
         <nested:text name="form1" property="ticketNo" />
         <nested:text name="form1" property="tranDate" />
         <nested:text name="form1" property="accountNo" />
         <nested:text name="form1" property="salesId" />
    </nested:iterate>
</html:form>

Doesn't matter if I use logic:iterate or nested:iterate, same results


EditRecordObject:
public class EditRecordObject {
    private String ticketNo = "";
    private String tranDate = "";
    private String accountNo = "";
    private String salesId = "";
                public EditRecordObject() {
	}
	
	public boolean getTicketNo() {
		return ticketNo;
	}
	
	public void setTicketNo(String val) {
		ticketNo = val;
	}
	etc...

Open in new window

0
Comment
Question by:kwatterson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 37734763
try with scope as request
0
 

Author Comment

by:kwatterson
ID: 37736281
When I use the request scope, after I submit the form, the request variable doesn't get reset.  When the JSP tries to come up the second time(after the submit action), it says, "cannot find bean in any scope". so it's not getting set again.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 37736448
you need to set the iterate list in session and try you will get the result
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kwatterson
ID: 37736473
I had my form variable EditUpdateForm as session and struts returned the original data, I changed the form variable to request and it doesn't get repopulated.   What do you mean set the iterate list in session?
0
 

Accepted Solution

by:
kwatterson earned 0 total points
ID: 37768602
My problem was that the action wasn't recognizing the changed variables.  I was getting IndexOutOfBounds errors as well, while using arrays and arraylists.  

I followed this example: http://laliluna.com/articles/posts/struts-nested-iteration-tutorial.html

got it to work and then back tracked to use my objects and varibles.

The key to my success was the reset method, I needed to initialize the form:

      public void reset(ActionMapping mapping,                                 HttpServletRequest request) {      //initial a dummy collection of customers            Collection customers = new ArrayList();            customers.add(new Customer(1, “Maria”));            customers.add(new Customer(2, “Klaus”));            customers.add(new Customer(3, “Peter”));            //initial a dummy department            department = new Department(1, “Department A”, customers);      }
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 37769880
gd work :)
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 38249561
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Introduction to Processes

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question