Re: DynaValidatorActionForm Setting Properties
Hi Pat, if you have to instantiate it yourself, you should call the initialize() method on the form first so that struts configures it to the struts-config settings. However that probably won't help in this case since your in-bound form doesn't work either. I doubt it would help, but you could try naming your class with an initial capitalized letter. Secondly, does the exception from the inbound form have a message? Regards Adam On 09/29/2003 01:35 PM Pat Quinn wrote: I have an Action to prepare a JSP view which uses a DynaValidatorActionForm. When i try to set a Form property i get a NullPointerException my source is as follows: - Struts-Config.xml - form-bean name=MyForm type=org.apache.struts.action.DynaValidatorActionForm form-property name=myTestTO type=com.mycompany.to.myTestTO/ /form-bean action path=/viewTest type=com.mycompany.actions.myTestAction scope=request input=my-tile-view name=MyForm validate=false forward name=success path=success-tile/ /action -- VALIDATION.xml -- form-validation formset form name=MyForm field property=myTestTO.name depends=required,minlength var var-nameminlength/var-name var-value10/var-value /var /field /form /formset /form-validation -- ACTION SOURCE CODE (i.e. com.mycompany.actions.myTestAction) -- DynaValidatorActionForm myForm = new DynaValidatorActionForm(); myForm.set(myTestTO, new myTestTO()); /* THROWS NullPointerException Here*/ pRequest.setAttribute(MyForm, myForm ); I've also tried casting the inbound ActionForm to DynaValidatorActionForm but i still get the same error when i invoke the set method. Any Ideas? _ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- struts 1.1 + tomcat 4.1.27 + java 1.4.2 Linux 2.4.20 RH9 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm Setting Properties
Hi Adam, Cheers for your efforts turns out it a silly mistake i've made i.e. i entered an invalid class name for my form defintion i.e. form-bean name=MyForm type=org.apache.struts.action.DynaValidatorActionForm Should be: form-bean name=MyForm type=org.apache.struts.validator.DynaValidatorActionForm Casting the inbound action form now works fine. Cheers Pat From: Adam Hardy [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Subject: Re: DynaValidatorActionForm Setting Properties Date: Mon, 29 Sep 2003 14:19:20 +0200 Hi Pat, if you have to instantiate it yourself, you should call the initialize() method on the form first so that struts configures it to the struts-config settings. However that probably won't help in this case since your in-bound form doesn't work either. I doubt it would help, but you could try naming your class with an initial capitalized letter. Secondly, does the exception from the inbound form have a message? Regards Adam On 09/29/2003 01:35 PM Pat Quinn wrote: I have an Action to prepare a JSP view which uses a DynaValidatorActionForm. When i try to set a Form property i get a NullPointerException my source is as follows: - Struts-Config.xml - form-bean name=MyForm type=org.apache.struts.action.DynaValidatorActionForm form-property name=myTestTO type=com.mycompany.to.myTestTO/ /form-bean action path=/viewTest type=com.mycompany.actions.myTestAction scope=request input=my-tile-view name=MyForm validate=false forward name=success path=success-tile/ /action -- VALIDATION.xml -- form-validation formset form name=MyForm field property=myTestTO.name depends=required,minlength var var-nameminlength/var-name var-value10/var-value /var /field /form /formset /form-validation -- ACTION SOURCE CODE (i.e. com.mycompany.actions.myTestAction) -- DynaValidatorActionForm myForm = new DynaValidatorActionForm(); myForm.set(myTestTO, new myTestTO()); /* THROWS NullPointerException Here*/ pRequest.setAttribute(MyForm, myForm ); I've also tried casting the inbound ActionForm to DynaValidatorActionForm but i still get the same error when i invoke the set method. Any Ideas? _ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- struts 1.1 + tomcat 4.1.27 + java 1.4.2 Linux 2.4.20 RH9 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] _ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm
Hmm., just realised the name of the form here is actually the action mapping path. Should I be naming the forms in validation.xml after the action mappings then rather than the form-beans from struts-config? Adam Hardy wrote: I set up the Validator to do automatic validation with normal action forms and it worked fine. Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm not getting server-side validation carried out. I see from delving into the source code for struts and commons-validator that the DynaValidatorAction form .validate() method is being called, but that the following line: Form form = resources.get(locale, formName); (578) returns a null form and so the validation is skipped. I've obviously missed something out on the set-up and config, but what? Can anybody cast a light on this? Meanwhile I'll carry on digging thanks Adam (struts 1.1 validator 1.0.2) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm
If you're using DynaValidatorActionForm, the name attribute of the form element in validation.xml should be the same as the path attribute of the action element in struts-config.xml. Quoting Adam Hardy [EMAIL PROTECTED]: Hmm., just realised the name of the form here is actually the action mapping path. Should I be naming the forms in validation.xml after the action mappings then rather than the form-beans from struts-config? Adam Hardy wrote: I set up the Validator to do automatic validation with normal action forms and it worked fine. Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm not getting server-side validation carried out. I see from delving into the source code for struts and commons-validator that the DynaValidatorAction form .validate() method is being called, but that the following line: Form form = resources.get(locale, formName); (578) returns a null form and so the validation is skipped. I've obviously missed something out on the set-up and config, but what? Can anybody cast a light on this? Meanwhile I'll carry on digging thanks Adam (struts 1.1 validator 1.0.2) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Kris Schneider mailto:[EMAIL PROTECTED] D.O.Tech http://www.dotech.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm
In that case then there won't be any javascript validation set up automatically! Is that the only difference between DynaValidatorActionForm and DynaValidatorForm? I still haven't got this working. although I'm one step further. Kris Schneider wrote: If you're using DynaValidatorActionForm, the name attribute of the form element in validation.xml should be the same as the path attribute of the action element in struts-config.xml. Quoting Adam Hardy [EMAIL PROTECTED]: Hmm., just realised the name of the form here is actually the action mapping path. Should I be naming the forms in validation.xml after the action mappings then rather than the form-beans from struts-config? Adam Hardy wrote: I set up the Validator to do automatic validation with normal action forms and it worked fine. Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm not getting server-side validation carried out. I see from delving into the source code for struts and commons-validator that the DynaValidatorAction form .validate() method is being called, but that the following line: Form form = resources.get(locale, formName); (578) returns a null form and so the validation is skipped. I've obviously missed something out on the set-up and config, but what? Can anybody cast a light on this? Meanwhile I'll carry on digging thanks Adam (struts 1.1 validator 1.0.2) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm
Okay, it sounded like you were just concerned with server-side validation. Try something like: head html:javascript formName=/action/path method=validateForm/ ... /head body ... html:form action=/action/path onsubmit=return validateForm(this); ... /body There are other best practices for organizing the static JavaScript, but try to get something working before worrying about that... Quoting Adam Hardy [EMAIL PROTECTED]: In that case then there won't be any javascript validation set up automatically! Is that the only difference between DynaValidatorActionForm and DynaValidatorForm? I still haven't got this working. although I'm one step further. Kris Schneider wrote: If you're using DynaValidatorActionForm, the name attribute of the form element in validation.xml should be the same as the path attribute of the action element in struts-config.xml. Quoting Adam Hardy [EMAIL PROTECTED]: Hmm., just realised the name of the form here is actually the action mapping path. Should I be naming the forms in validation.xml after the action mappings then rather than the form-beans from struts-config? Adam Hardy wrote: I set up the Validator to do automatic validation with normal action forms and it worked fine. Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm not getting server-side validation carried out. I see from delving into the source code for struts and commons-validator that the DynaValidatorAction form .validate() method is being called, but that the following line: Form form = resources.get(locale, formName); (578) returns a null form and so the validation is skipped. I've obviously missed something out on the set-up and config, but what? Can anybody cast a light on this? Meanwhile I'll carry on digging thanks Adam (struts 1.1 validator 1.0.2) -- Kris Schneider mailto:[EMAIL PROTECTED] D.O.Tech http://www.dotech.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm
Sorry, panicing for a moment there :O - OK, I see the way the javascript tag works. It seems there no long validate function? I think I have found the cause of my problem. In my dynaform definition, I set my id field type to Long - and when I enter a non-Long value in the form, the dynaform rejects it first and the dynaform long value remains null - therefore the validateLong() method will ignore it, because the validate long method can only validate a string. Is that so? Should I keep all my fields as strings in my form definition? txs Adam Kris Schneider wrote: Okay, it sounded like you were just concerned with server-side validation. Try something like: head html:javascript formName=/action/path method=validateForm/ ... /head body ... html:form action=/action/path onsubmit=return validateForm(this); ... /body There are other best practices for organizing the static JavaScript, but try to get something working before worrying about that... Quoting Adam Hardy [EMAIL PROTECTED]: In that case then there won't be any javascript validation set up automatically! Is that the only difference between DynaValidatorActionForm and DynaValidatorForm? I still haven't got this working. although I'm one step further. Kris Schneider wrote: If you're using DynaValidatorActionForm, the name attribute of the form element in validation.xml should be the same as the path attribute of the action element in struts-config.xml. Quoting Adam Hardy [EMAIL PROTECTED]: Hmm., just realised the name of the form here is actually the action mapping path. Should I be naming the forms in validation.xml after the action mappings then rather than the form-beans from struts-config? Adam Hardy wrote: I set up the Validator to do automatic validation with normal action forms and it worked fine. Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm not getting server-side validation carried out. I see from delving into the source code for struts and commons-validator that the DynaValidatorAction form .validate() method is being called, but that the following line: Form form = resources.get(locale, formName); (578) returns a null form and so the validation is skipped. I've obviously missed something out on the set-up and config, but what? Can anybody cast a light on this? Meanwhile I'll carry on digging thanks Adam (struts 1.1 validator 1.0.2) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm
Yes, keep your form bean properties typed as String. Of course, there are reasonable exceptions to the rule (e.g. nested, mapped, and indexed properties). Otherwise, as you've observed, your form fields won't get repopulated with the bad data upon validation failures. Adam Hardy wrote: Sorry, panicing for a moment there :O - OK, I see the way the javascript tag works. It seems there no long validate function? I think I have found the cause of my problem. In my dynaform definition, I set my id field type to Long - and when I enter a non-Long value in the form, the dynaform rejects it first and the dynaform long value remains null - therefore the validateLong() method will ignore it, because the validate long method can only validate a string. Is that so? Should I keep all my fields as strings in my form definition? txs Adam Kris Schneider wrote: Okay, it sounded like you were just concerned with server-side validation. Try something like: head html:javascript formName=/action/path method=validateForm/ ... /head body ... html:form action=/action/path onsubmit=return validateForm(this); ... /body There are other best practices for organizing the static JavaScript, but try to get something working before worrying about that... Quoting Adam Hardy [EMAIL PROTECTED]: In that case then there won't be any javascript validation set up automatically! Is that the only difference between DynaValidatorActionForm and DynaValidatorForm? I still haven't got this working. although I'm one step further. Kris Schneider wrote: If you're using DynaValidatorActionForm, the name attribute of the form element in validation.xml should be the same as the path attribute of the action element in struts-config.xml. Quoting Adam Hardy [EMAIL PROTECTED]: Hmm., just realised the name of the form here is actually the action mapping path. Should I be naming the forms in validation.xml after the action mappings then rather than the form-beans from struts-config? Adam Hardy wrote: I set up the Validator to do automatic validation with normal action forms and it worked fine. Now I'm trying to incorporate dynaforms but I'm not having any luck. I'm not getting server-side validation carried out. I see from delving into the source code for struts and commons-validator that the DynaValidatorAction form .validate() method is being called, but that the following line: Form form = resources.get(locale, formName); (578) returns a null form and so the validation is skipped. I've obviously missed something out on the set-up and config, but what? Can anybody cast a light on this? Meanwhile I'll carry on digging thanks Adam (struts 1.1 validator 1.0.2) -- Kris Schneider mailto:[EMAIL PROTECTED] D.O.Tech http://www.dotech.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm
On Thu, 27 Feb 2003 14:34:23 -0500 Sloan Seaman [EMAIL PROTECTED] wrote: For my edit page, how do I populate a bean for the edit page to use to populate the fields? From what I've been reading it seems like I don't ahve to write a form class anymore because of the DynaActionForm stuff, but I'm a bit confused. I like to first set up my page by having a mapping submit to a setUp Action. Then in this setUp action you could just do: DynaActionForm f = (DynaActionForm) form; f.set(firstName, John Doe); //etc. then you would just forward to the jsp form. -- Rick Reumann - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DynaValidatorActionForm
Rick Reumann wrote: Sloan Seaman wrote: For my edit page, how do I populate a bean for the edit page to use to populate the fields? From what I've been reading it seems like I don't ahve to write a form class anymore because of the DynaActionForm stuff, but I'm a bit confused. I like to first set up my page by having a mapping submit to a setUp Action. Then in this setUp action you could just do: DynaActionForm f = (DynaActionForm) form; f.set(firstName, John Doe); then you would just forward to the jsp form. I solved this problem quasi-generically (I depend on an ID field in my beans, at least for now) by writing a CrudDispatchAction that gets the bean class from a standardized name in the resource bundle (i.e., the name attribute in the action configuration is the prefix for the classname and I append a .classname to it to find the appropriate class). I've appended my CrudDispatchAction class below (it's very alpha and not robust, it's a work in progress :) and I'd love to hear any comments on it regarding style issues, robustification, struts paradigms, whether or not this is even a good idea, you name it. I'm the only programmer here so feedback is lacking :( I left out the doCreate method since I haven't done the general purpose one yet and I would expect some refactoring to happen (for instance the Class instantiation stuff will go into a base class because I'm already planning to subclass this for some other purposes). Thanks, Dave Newton // Here it is // [...] public class CrudDispatchAction extends DispatchAction { /** * Logger instance */ private Log log = LogFactory.getFactory().getInstance(this.getClass().getName()); /** * List collection of items. Assumes that the class name of the * database bean is in the resources file. */ public ActionForward doList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionForward resultForward = mapping.findForward(errjsp); log.info(enter); DBRow rows = getRowObject(mapping, request); try { rows.select(); request.setAttribute(rows, rows.getRows()); resultForward = mapping.findForward(listjsp); } catch (SolarException x) { throw new ModuleException(global.exception.db); } return resultForward; } /** * Delete an item based on ID */ public ActionForward doDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { int id = StringUtil.parseInt(request.getParameter(id)); log.info(entering to delete id= + id); DBRow row = getRowObject(mapping, request); row.deleteById(id); return mapping.findForward(listact); } /** * Edit an item based on ID */ public ActionForward doEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { int id = StringUtil.parseInt(request.getParameter(id)); log.info(entering to edit id= + id); // If GET then populate form and go to editing page if (request.getMethod().equals(GET)) { DBRow row = getRowObject(mapping, request); if (row.selectById(id)) { PropertyUtils.copyProperties(form, row); return mapping.findForward(mapping.getInput()); } else { return mapping.findForward(notfound); } } // We've edited; validate ActionErrors errs = form.validate(mapping, request); if ((errs != null) !errs.isEmpty()) { saveErrors(request, errs); return mapping.findForward(mapping.getInput()); } // We've validated; update ActionForward ret = mapping.findForward(listact); // Assume success try { DBRow row = getRowObject(mapping, request); PropertyUtils.copyProperties(row, form); if (row.updateById(id) == 0) { // it didn't update errs = new ActionErrors(); errs.add(systemerror, new ActionError(global.system.error)); // TODO system error key constant saveErrors(request, errs); return mapping.findForward(mapping.getInput()); } } catch (SolarException sae) { throw new ModuleException(global.exception.db); } catch (ModuleException me) { throw me; } return
Re: DynaValidatorActionForm/DynaValidatorAction
DynaValidatorForm just extends DynaActionForm and overrides the validate method. From a discussion on the dev list I was under the impression that it would work the same, but I didn't have time to test them or make examples. I was rushed to get them into the beta. If you can't just replace DynaValidatorForm in a working DynaActionForm, could you file a bug in bugzilla so it doesn't get missed and definitely gets fixed for Struts 1.1? http://nagoya.apache.org/bugzilla/ ValidatorForm DynaValidatorForm use mapping.getAttribute() to retrieve the form DynaActionForm DynaValidatorActionForm use mapping.getPath() to retrieve a form David --- Phase Web and Multimedia [EMAIL PROTECTED] wrote: Can someone please give me a snippet of code that uses these classes properly. I have found no examples. Perhaps because it is new, maybe. But, I have tried to use it like the DynaActionForm in my form-bean declaration and I have tried to cast it from the ActionForm form in my Action class to both DynaValidatorActionForm and DynaValidatorForm. On the first one I get a null pointer exception on the getProperty(...) and on the latter I get ClassCastExcpetion. I am not sure what I am doing. But, can someone provide an explanation or example. I've got a better understanding of the DynaActionForm. Now, I need some help with DynaValidatorActionForm and DynaValidatorAction. Also, why the two different DynaValidator classes. What are the differences between the two besides logging? Brandon Goodin Phase Web and Multimedia P (406) 862-2245 F (406) 862-0354 [EMAIL PROTECTED] http://www.phase.ws -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] __ Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax http://taxes.yahoo.com/ -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: DynaValidatorActionForm
I don't see anything wrong, but I wrote the javadoc so I might be missing something. DynaValidatorForm - uses the name of your form bean (registrationForm) to retrieve the set of validation rules DynaValidatorActionForm - uses the name of your action (/registration) to retrieve the set of validation rules These just give you a choice how you want to handle storing/retrieving your validation rules. The form element's name attribute in the validation.xml is just a key used to store and retrieve a set of validation rules. David --- See Yam Lim [EMAIL PROTECTED] wrote: The key passed into the validator is the action element's 'path' attribute from the struts-config.xml which should match the form element's name attribute in the validation.xml. Validator validator = StrutsValidatorUtil.initValidator(mapping.getPath(), this, application, request, errors, page); i found the above javadoc and code that in DynaValidatorActionForm which i think it should be the action element's 'name' attribute from the struts-config.xml to form element's name attribute in the validation.xml. Can anyone confirm me on that or tell me why otherwise? Thanks so much! See-Yam Lim __ Do You Yahoo!? Yahoo! Movies - coverage of the 74th Academy Awards® http://movies.yahoo.com/ -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: DynaValidatorActionForm
Thanks David. That's great! I got it now. -Original Message- From: David Winterfeldt [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 2:14 PM To: Struts Users Mailing List Subject: Re: DynaValidatorActionForm I don't see anything wrong, but I wrote the javadoc so I might be missing something. DynaValidatorForm - uses the name of your form bean (registrationForm) to retrieve the set of validation rules DynaValidatorActionForm - uses the name of your action (/registration) to retrieve the set of validation rules These just give you a choice how you want to handle storing/retrieving your validation rules. The form element's name attribute in the validation.xml is just a key used to store and retrieve a set of validation rules. David --- See Yam Lim [EMAIL PROTECTED] wrote: The key passed into the validator is the action element's 'path' attribute from the struts-config.xml which should match the form element's name attribute in the validation.xml. Validator validator = StrutsValidatorUtil.initValidator(mapping.getPath(), this, application, request, errors, page); i found the above javadoc and code that in DynaValidatorActionForm which i think it should be the action element's 'name' attribute from the struts-config.xml to form element's name attribute in the validation.xml. Can anyone confirm me on that or tell me why otherwise? Thanks so much! See-Yam Lim __ Do You Yahoo!? Yahoo! Movies - coverage of the 74th Academy Awards® http://movies.yahoo.com/ -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]