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
  <html:form action="/testingSaveAction" method="post">
  logic:iterate name="testingForm" property="listOfItems" id="labelValue">
  Indexed field to be validated: <html:text name="labelValue" property="value" 
indexed="true"/><br />
  /logic:iterate> 
  <html:submit property="submit">Save</html:submit>
  </html:form>
   
  In validaton.xml I set up the validation for the indexed filed:
<formset>
 <form name="/testingSaveAction"> 
      <field property="value" indexedListProperty="listOfItems" 
depends="required">
             <msg name="required" key="thisfield.cannotblank"/>
       </field>
          
 </form>
</formset>

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

Reply via email to