OK, so when validation fails Struts forwards to displayTesting which, in turn, forwards to /displayAction. In your DisplayAction class, you're overwriting the values of your form bean property, destroying the information Struts set there.

You'll need to check if the property has already been initialized and not overwrite its values if it has any. Alternatively, you could move the code for initializing the property in the form bean's reset() method, but probably leaving it where it is and wrapping it in a guard would be a better bet.

Alternatively, split your DisplayAction into two actions, one to do the initial setup and one to handle re-display of the form. In either case, to goal is to not trample the data in the form during re-display.

L.

Carl Smith wrote:
First of all Thank you Laurie, you are the only one anwering my questions :):
Here are my struts-config.xml entries for the actions and formbean ( I neglected the path and anything). <form-beans> <form-bean name="testingForm" type="TestingForm" /> </form-beans> <global-forwards>
 <forward name="displayTesting" path="/displayAction.do"/>
</global-forwards>
<action-mappings> <action path="/displayAction" type="DisplayAction" name="testingForm" scope="session" validate="false" >
  </action>
<action path="/testingSaveAction" type="TestingSaveAction" name="testingForm" scope="session" validate="true" input="displayTesting"> <forward name="success" path="susscess.jsp" /> </action> </action-mappings>
Laurie Harper <[EMAIL PROTECTED]> wrote:
We'll need to see the relevant parts of your struts-config.xml too (specifically, the form bean and action mapping definitions).

L.

Carl Smith wrote:
I have a jsp containing an indexed test box field, and I need to validate the 
user enter a value into all the text boxes when clicking on the save button. 
Validation is done OK, but there is an issue. Let me give you an example 
illustrating the issue: if there are three text boxes, the user enters 1, 2 
into the first two boxes, but didn't enter anything in the third box, struts 
validation catch and display the correct validation error on the jsp saying 
he/she needs to enter values for all the text boxes, then it wipes out 1 and 2, 
which is not what I wanted. What I wanted was that when displaying the 
validation error, it should keep 1 and 2 which was entered by the user. Any 
suggestions? I appreciate your helps!

Here are my classes:

public class TestingForm extends ValidatorActionForm {
private LabelValueBean[] listOfItems ;
public LabelValueBean[] getListOfItems() {
return listOfItems;
}
public void setListOfItems(LabelValueBean[] beans) {
listOfItems = beans;
}
}
public class DisplayAction extends org.apache.struts.action.Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws NestedException {

TestingForm testingForm = (TestingForm) form;
LabelValueBean[] listOfItems = new LabelValueBean[3];

LabelValueBean bean1 = new LabelValueBean("1", "");
LabelValueBean bean2 = new LabelValueBean("2", "");
LabelValueBean bean3 = new LabelValueBean("3", "");
listOfItems[0]=bean1;
listOfItems[1]=bean2;
listOfItems[2]=bean3;

testingForm.setListOfItems(listOfItems);
return mapping.findForward("myJsp.jsp");
}
}
myJsp.jsp

logic:iterate name="testingForm" property="listOfItems" id="labelValue">
Indexed field to be validated:

/logic:iterate> Save


In validaton.xml I set up the validation for the indexed filed:








---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ 
countries) for 2?min or less.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



                        
---------------------------------
Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to