Solved

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

Posted on 2012-03-17
8
435 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

749 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