Solved

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

Posted on 2012-03-17
8
430 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

773 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