You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Carl Smith <cc...@yahoo.com> on 2006/04/10 20:59:15 UTC

indexed property validation error:java.lang.reflect.InvocationTargetException

I have a jsp containing three text fields which are indexed property, I needs to validate all the text box contains a value other than null or empth string. When I click on save I got the error (see the bottom). Your helps are highly appreciated!
   
  jsp:
  <html:errors/>
<html:form action="/testingSaveAction" method="post">
 
 (1) indexed property - text box
 <br />
 <logic:iterate name="testingForm" property="listOfItems" id="labelValue">
 Fields to be validated: <html:text name="labelValue" property="value" indexed="true"/><br />
 </logic:iterate> 
 <br /><br />
   <html:submit property="submit">save</html:submit>
  </html:form>  
   
  ActionForm:
public class TestingForm extends ValidatorActionForm {
     
 private LabelValueBean[] listOfItems;
 private LabelValueBean labelValue=null;
 
 
 public LabelValueBean getLabelValue(int index) {
  return (LabelValueBean)listOfItems[index];
 }
 
 public void setLabelValue(LabelValueBean bean, int index) {
  listOfItems[index]= bean;
 }
   public LabelValueBean[] getListOfItems() {
  return listOfItems;
 }
   public void setListOfItems(LabelValueBean[] beans) {
  listOfItems = beans;
 }   
}
   
  Actions:
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;
  
  if (null == testingForm || null ==testingForm.getListOfItems()) {
   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("success");
 }
}
  
public class TestingSaveAction extends org.apache.struts.action.Action{
   
 public ActionForward executeAction(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response)
  throws NestedException {
  
  TestingForm testingForm = (TestingForm) form;
  
  return mapping.findForward("success");
 }
   
  struts-config.xml
<global-forwards>
       <forward name="displayTesting" path="/displayAction.do"/>
</global-forwards>
  <form-bean name="testingForm" type="MyPath.TestingForm" />
  <action path="/displayAction" type="MyPath.DisplayAction" 
  name="testingForm" scope="request" 
  validate="false" >
  <forward name="success" path="/MyPath/testing.jsp" /> 
</action>
  
<action path="/testingSaveAction" type="MyPath.TestingSaveAction" 
  name="testingForm" scope="request" 
  validate="true" input="displayTesting">
  <forward name="success" path="/MyPath/successful.jsp" />  
</action> 
 
  validation.xml
 <form name="/testingSaveAction"> 
          <field property="value" indexedListProperty="listOfItems" depends="required">
             <msg name="required" key="Keytoerrormessage.cannotblank"/>
   </field>
          
  </form>
  
 
  Errors when click on save:
E SRVE0026E: [Servlet Error]-[BeanUtils.populate]: java.lang.reflect.InvocationTargetException: java.lang.NullPointerException
 at MyPath.TestingForm.getLabelValue(TestingForm.java:75)
 at java.lang.reflect.Method.invoke(Native Method)
 at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:493)
  where line 75 is the place: return (LabelValueBean)listOfItems[index]; in the actionform
  

 

		
---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1&cent;/min.

ActionForm and JavaBean Specifications

Posted by Carl Smith <cc...@yahoo.com>.
  JavaBeans Specification doesn't allow more than one setter method (with different argument signatures) for the same property, in other words, JavaBeans specification doesn't allow the method overloading for property setters, does this also apply for Struts ActionForms? Is so, why I did have an over loaded getter methods in an ActionForm and it works fine?
   
  Thanks.
   

		
---------------------------------
Love cheap thrills? Enjoy PC-to-Phone  calls to 30+ countries for just 2ยข/min with Yahoo! Messenger with Voice.