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

2006-04-12 Thread Michael TALLET
Hello Carl, 

1) it works with a sessionScope ActionForm because it keeps the first one you 
populate at hand in the DisplayAction

2) with requestScope you have to create your object by hand

public LabelValueBean getLabelValue(int index) {
if (listOfItems == null) {
listOfItems = new LabelValueBean[3]; // if size changes adapt...
}
LabelValueBean bean = listOfItems[index];
if (bean ==null){
bean = new LabelValueBean();
listOfItems[index] = bean;
}
return bean;
}

The RequestUtils.processPopulate will call setValue on the bean, and that's all

Hope this helps


-Message d'origine-
De : Carl Smith [mailto:[EMAIL PROTECTED] 
Envoyé : mercredi 12 avril 2006 00:21
À : Struts Users Mailing List
Objet : Re: indexed property validation 
error:java.lang.reflect.InvocationTargetException

Interestingly if I change the config for testingForm to be of scope session, 
then it works. However I can't use session scope so still need the answer for 
my original question, can some one help? Thanks.
  
Carl Smith <[EMAIL PROTECTED]> wrote:
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:
  

 
 (1) indexed property - text box
 
 
 Fields to be validated: 
  
 
   save

   
  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

   

  
  
   

  


 
 
  validation.xml
  
  
 
   
  
  
  
 
  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¢/min.



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

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



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

2006-04-11 Thread Carl Smith
Interestingly if I change the config for testingForm to be of scope session, 
then it works. However I can't use session scope so still need the answer for 
my original question, can some one help? Thanks.
  
Carl Smith <[EMAIL PROTECTED]> wrote:
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:
  

 
 (1) indexed property - text box
 
 
 Fields to be validated: 
  
 
   save

   
  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

   

  
  
   

  


 
 
  validation.xml
  
  
 
   
  
  
  
 
  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¢/min.



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