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
Solved

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

Posted on 2012-03-17
8
434 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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.

839 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