Any Takers ?RE: Struts Validator and Select boxes
Any help/takers ? -Original Message- From: Janarthan Sathiamurthy Sent: Thursday, March 25, 2004 10:16 PM To: [EMAIL PROTECTED] Subject: Struts Validator and Select boxes Hi, I am using Struts validator. One page of mine has dates displayed as MM DD . All the above 3 are displayed in seprate combo/select boxes. I need to do some custom validations on these fields. I wrote a custom class for the same Looks like - public static boolean validateDates(Object bean, ValidatorAction validatorAction, Field field, ActionErrors errors, HttpServletRequest request) { String actionType = ValidatorUtil.getValueAsString(bean, field.getVarValue(actionType)); // A hidden form field String fromMonth = ValidatorUtil.getValueAsString(bean, field.getProperty()); String fromDay = ValidatorUtil.getValueAsString(bean, field.getVarValue(fromDay)); String fromYear = ValidatorUtil.getValueAsString(bean, field.getVarValue(fromYear)); String toMonth = ValidatorUtil.getValueAsString(bean, field.getVarValue(toMonth)); String toDay = ValidatorUtil.getValueAsString(bean, field.getVarValue(toDay)); String toYear = ValidatorUtil.getValueAsString(bean, field.getVarValue(toYear)); System.out.println(actionType + actionType); System.out.println(fromMonth + fromMonth); System.out.println(fromDay + fromDay); System.out.println(fromYear + fromYear); System.out.println(toMonth + toMonth); System.out.println(toDay + toDay); System.out.println(toYear + toYear); return true; } O/P of the above code - actionType searchPage fromMonth 2 fromDay null fromYear null toMonth null toDay null toYear null It also gives me No Name Specified error. Point to note is that the all other fields other than 'actionType' are select boxes. It gives a null for all the field types that are of html:select. Is this a known BUG or am i going wrong somewhere ? Error LOG - Mar 25, 2004 9:53:11 PM org.apache.commons.validator.ValidatorUtil getValueAsString SEVERE: No name specified java.lang.IllegalArgumentException: No name specified at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:721) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801) at org.apache.commons.validator.ValidatorUtil.getValueAsString(ValidatorUtil.java:121) at com.mot.servicetools.util.OCSReportsDateValidator.validateDates(OCSReportsDateValidator.j ava:55) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.validator.Validator.validateFieldForRule(Validator.java:454) at org.apache.commons.validator.Validator.validateField(Validator.java:544) at org.apache.commons.validator.Validator.validate(Validator.java:582) at org.apache.struts.validator.DynaValidatorActionForm.validate(DynaValidatorActionForm.java :125) at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:942) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.jav a:1053) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletC ontext.java:6310) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:36 22) at weblogic.servlet.internal.ServletRequestImpl.execute
Re: Struts Validator and Select boxes
Posting whats in your validation.xml for the form and the bit of your jsp with your select fields would be helpfull. If you take the fromDay as an example, you are using field.getVarValue(fromDay) - if you don't have a var defined in your validation.xml for fromDay then that would cause the No Name Specified error - same goes for fromYear, toMonth, toDay and toYear. As for getting nulls, looks to me again that whats specified for the vars in your validation.xml doesn't tie up with the names specified on your form. From your code I would expect something like the following in your validation.xml form. field varvar-namefromDay/var-name var-valueformFromDay/var-value /var varvar-namefromYear/var-name var-valueformFromYear/var-value /var varvar-nametoMonth/var-name var-valueformToMonth/var-value /var varvar-nametoDay/var-name var-valueformToDay/var-value /var varvar-nametoYear/var-name var-valueformToYear/var-value /var /field /form Do you have the properties in your form correct (i.e in this example formFromDay, formFromYear, formToMonth, formToDay, formToYear). Niall - Original Message - From: Janarthan Sathiamurthy [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, March 25, 2004 4:46 PM Subject: Struts Validator and Select boxes Hi, I am using Struts validator. One page of mine has dates displayed as MM DD . All the above 3 are displayed in seprate combo/select boxes. I need to do some custom validations on these fields. I wrote a custom class for the same Looks like - public static boolean validateDates(Object bean, ValidatorAction validatorAction, Field field, ActionErrors errors, HttpServletRequest request) { String actionType = ValidatorUtil.getValueAsString(bean, field.getVarValue(actionType)); // A hidden form field String fromMonth = ValidatorUtil.getValueAsString(bean, field.getProperty()); String fromDay = ValidatorUtil.getValueAsString(bean, field.getVarValue(fromDay)); String fromYear = ValidatorUtil.getValueAsString(bean, field.getVarValue(fromYear)); String toMonth = ValidatorUtil.getValueAsString(bean, field.getVarValue(toMonth)); String toDay = ValidatorUtil.getValueAsString(bean, field.getVarValue(toDay)); String toYear = ValidatorUtil.getValueAsString(bean, field.getVarValue(toYear)); System.out.println(actionType + actionType); System.out.println(fromMonth + fromMonth); System.out.println(fromDay + fromDay); System.out.println(fromYear + fromYear); System.out.println(toMonth + toMonth); System.out.println(toDay + toDay); System.out.println(toYear + toYear); return true; } O/P of the above code - actionType searchPage fromMonth 2 fromDay null fromYear null toMonth null toDay null toYear null It also gives me No Name Specified error. Point to note is that the all other fields other than 'actionType' are select boxes. It gives a null for all the field types that are of html:select. Is this a known BUG or am i going wrong somewhere ? Error LOG - Mar 25, 2004 9:53:11 PM org.apache.commons.validator.ValidatorUtil getValueAsString SEVERE: No name specified java.lang.IllegalArgumentException: No name specified at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.j ava:721) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:80 1) at org.apache.commons.validator.ValidatorUtil.getValueAsString(ValidatorUtil.ja va:121) at com.mot.servicetools.util.OCSReportsDateValidator.validateDates(OCSReportsDa teValidator.j ava:55) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.validator.Validator.validateFieldForRule(Validator.java:4 54) at org.apache.commons.validator.Validator.validateField(Validator.java:544) at org.apache.commons.validator.Validator.validate(Validator.java:582) at org.apache.struts.validator.DynaValidatorActionForm.validate(DynaValidatorAc tionForm.java :125) at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.j ava:942) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525
RE: Struts Validator and Select boxes
Hi Niall, I am attaching the validation.xml and the jsp that i have used. I have done the exact thing that you had specified earlier before posting to the mailing list. I am not clear where i am going wrong. The Struts-config entry goes like - form-bean name=ocsReportForm type=org.apache.struts.validator.DynaValidatorActionForm form-property name=monthFrom type=java.lang.String / form-property name=dayFrom type=java.lang.String / form-property name=yearFrom type=java.lang.String / form-property name=monthTo type=java.lang.String / form-property name=dayTo type=java.lang.String / form-property name=yearTo type=java.lang.String / form-property name=actionType type=java.lang.String / form-property name=pageNumber type=java.lang.String / form-property name=numberOfRows type=java.lang.String / form-property name=dateFrom type=java.lang.String / form-property name=dateTo type=java.lang.String / /form-bean Regards, Janarthan S -Original Message- From: Niall Pemberton [mailto:[EMAIL PROTECTED] Sent: Friday, March 26, 2004 8:55 PM To: Struts Users Mailing List Subject: Re: Struts Validator and Select boxes Posting whats in your validation.xml for the form and the bit of your jsp with your select fields would be helpfull. If you take the fromDay as an example, you are using field.getVarValue(fromDay) - if you don't have a var defined in your validation.xml for fromDay then that would cause the No Name Specified error - same goes for fromYear, toMonth, toDay and toYear. As for getting nulls, looks to me again that whats specified for the vars in your validation.xml doesn't tie up with the names specified on your form. From your code I would expect something like the following in your validation.xml form. field varvar-namefromDay/var-name var-valueformFromDay/var-value /var varvar-namefromYear/var-name var-valueformFromYear/var-value /var varvar-nametoMonth/var-name var-valueformToMonth/var-value /var varvar-nametoDay/var-name var-valueformToDay/var-value /var varvar-nametoYear/var-name var-valueformToYear/var-value /var /field /form Do you have the properties in your form correct (i.e in this example formFromDay, formFromYear, formToMonth, formToDay, formToYear). Niall - Original Message - From: Janarthan Sathiamurthy [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, March 25, 2004 4:46 PM Subject: Struts Validator and Select boxes Hi, I am using Struts validator. One page of mine has dates displayed as MM DD . All the above 3 are displayed in seprate combo/select boxes. I need to do some custom validations on these fields. I wrote a custom class for the same Looks like - public static boolean validateDates(Object bean, ValidatorAction validatorAction, Field field, ActionErrors errors, HttpServletRequest request) { String actionType = ValidatorUtil.getValueAsString(bean, field.getVarValue(actionType)); // A hidden form field String fromMonth = ValidatorUtil.getValueAsString(bean, field.getProperty()); String fromDay = ValidatorUtil.getValueAsString(bean, field.getVarValue(fromDay)); String fromYear = ValidatorUtil.getValueAsString(bean, field.getVarValue(fromYear)); String toMonth = ValidatorUtil.getValueAsString(bean, field.getVarValue(toMonth)); String toDay = ValidatorUtil.getValueAsString(bean, field.getVarValue(toDay)); String toYear = ValidatorUtil.getValueAsString(bean, field.getVarValue(toYear)); System.out.println(actionType + actionType); System.out.println(fromMonth + fromMonth); System.out.println(fromDay + fromDay); System.out.println(fromYear + fromYear); System.out.println(toMonth + toMonth); System.out.println(toDay + toDay); System.out.println(toYear + toYear); return true; } O/P of the above code - actionType searchPage fromMonth 2 fromDay null fromYear null toMonth null toDay null toYear null It also gives me No Name Specified error. Point to note is that the all other fields other than 'actionType' are select boxes. It gives a null for all the field types that are of html:select. Is this a known BUG or am i going wrong somewhere ? Error LOG - Mar 25, 2004 9:53:11 PM org.apache.commons.validator.ValidatorUtil getValueAsString SEVERE: No name specified java.lang.IllegalArgumentException: No name specified
Struts Validator and Select boxes
Hi, I am using Struts validator. One page of mine has dates displayed as MM DD . All the above 3 are displayed in seprate combo/select boxes. I need to do some custom validations on these fields. I wrote a custom class for the same Looks like - public static boolean validateDates(Object bean, ValidatorAction validatorAction, Field field, ActionErrors errors, HttpServletRequest request) { String actionType = ValidatorUtil.getValueAsString(bean, field.getVarValue(actionType)); // A hidden form field String fromMonth = ValidatorUtil.getValueAsString(bean, field.getProperty()); String fromDay = ValidatorUtil.getValueAsString(bean, field.getVarValue(fromDay)); String fromYear = ValidatorUtil.getValueAsString(bean, field.getVarValue(fromYear)); String toMonth = ValidatorUtil.getValueAsString(bean, field.getVarValue(toMonth)); String toDay = ValidatorUtil.getValueAsString(bean, field.getVarValue(toDay)); String toYear = ValidatorUtil.getValueAsString(bean, field.getVarValue(toYear)); System.out.println(actionType + actionType); System.out.println(fromMonth + fromMonth); System.out.println(fromDay + fromDay); System.out.println(fromYear + fromYear); System.out.println(toMonth + toMonth); System.out.println(toDay + toDay); System.out.println(toYear + toYear); return true; } O/P of the above code - actionType searchPage fromMonth 2 fromDay null fromYear null toMonth null toDay null toYear null It also gives me No Name Specified error. Point to note is that the all other fields other than 'actionType' are select boxes. It gives a null for all the field types that are of html:select. Is this a known BUG or am i going wrong somewhere ? Error LOG - Mar 25, 2004 9:53:11 PM org.apache.commons.validator.ValidatorUtil getValueAsString SEVERE: No name specified java.lang.IllegalArgumentException: No name specified at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:721) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801) at org.apache.commons.validator.ValidatorUtil.getValueAsString(ValidatorUtil.java:121) at com.mot.servicetools.util.OCSReportsDateValidator.validateDates(OCSReportsDateValidator.j ava:55) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.validator.Validator.validateFieldForRule(Validator.java:454) at org.apache.commons.validator.Validator.validateField(Validator.java:544) at org.apache.commons.validator.Validator.validate(Validator.java:582) at org.apache.struts.validator.DynaValidatorActionForm.validate(DynaValidatorActionForm.java :125) at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:942) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.jav a:1053) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletC ontext.java:6310) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:36 22) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170) Thanks Regards, Janarthan S.