Solved

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

Posted on 2012-03-17
8
421 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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.
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now