Re: validation with annotation
The current usage of Annotating methods seems broken. Its still applying all the validation rules to all methods despite methods having different validation requirements. The Struts Zero Config/Annotation/Auto Config needs help Hopefully, a http://jira.opensymphony.com/browse/XW-603 sprinkling of sane configuration of inheritance (though xml) will add power, and reduce redundant configuration code. re: http://jira.opensymphony.com/browse/XW-603 Matt Ealden Escañan wrote: On Tue, Mar 11, 2008 at 7:10 AM, xianwinwin [EMAIL PROTECTED] wrote: assuming registration is composed of fname, lname, ss, dob and except dob all fields are mandatory. Question: how do I make sure those fields will be input? should I have something like: @RequiredStringValidator(message=Legal Name is missing) private setFname(String fn) on the registration - if so - wouldn't that effect other classes that uses registration??? thanks for any input! Hi xianwinwin, You can annotate an action method with @Validations and validate from there, ie: @Validations( requiredString = { @RequiredFieldValidator( type=ValidatorType.FIELD, fieldName=registration.fname message=Foo! ) } ) public String save() { ... } http://struts.apache.org/2.x/docs/validation-annotation.html Admittedly, I used this approach these past few days and found myself back to validations in XML: http://blog.ealden.net/2008/03/working-with-struts-2-validators.html Thanks -- Ealden Esto E. Escañan http://blog.ealden.net - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/validation-with-annotation-tp15966492p16039860.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: validation with annotation
On Wed, Mar 12, 2008 at 4:17 AM, xianwinwin [EMAIL PROTECTED] wrote: Thanks Ealden, this was very helpful! I tried that and it works fine. Question, say I wish to check for a date, so far I've been doing it this way: example private Date delta; @TypeConversion(converter=com.utilities.conversion.DateTypeConversion) public void setDelta(Date delta) { this.delta = delta; } Obviously the I created the converter. How can I incorporate this TypeConversion into the Action Annotation (say to field registration.dob)? @Validations(...what comes here.???...) public String save() { //some code } Xianwinwin, There should be a conversion error interceptor in, say, defaultStack, that prompts the user if a conversion fails such as when the date entered is not correct. A case that needs to be handled though is if the user didn't enter any date at all which doesn't seem to cause a conversion error. Since you are using a custom type converter I suppose you can catch this case. Thanks -- Ealden Esto E. Escañan http://blog.ealden.net - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: validation with annotation
Thanks Ealden, this was very helpful! I tried that and it works fine. Question, say I wish to check for a date, so far I've been doing it this way: example private Date delta; @TypeConversion(converter=com.utilities.conversion.DateTypeConversion) public void setDelta(Date delta) { this.delta = delta; } Obviously the I created the converter. How can I incorporate this TypeConversion into the Action Annotation (say to field registration.dob)? @Validations(...what comes here.???...) public String save() { //some code } Thank you! -- View this message in context: http://www.nabble.com/validation-with-annotation-tp15966492p15988555.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: validation with annotation
On Tue, Mar 11, 2008 at 7:10 AM, xianwinwin [EMAIL PROTECTED] wrote: assuming registration is composed of fname, lname, ss, dob and except dob all fields are mandatory. Question: how do I make sure those fields will be input? should I have something like: @RequiredStringValidator(message=Legal Name is missing) private setFname(String fn) on the registration - if so - wouldn't that effect other classes that uses registration??? thanks for any input! Hi xianwinwin, You can annotate an action method with @Validations and validate from there, ie: @Validations( requiredString = { @RequiredFieldValidator( type=ValidatorType.FIELD, fieldName=registration.fname message=Foo! ) } ) public String save() { ... } http://struts.apache.org/2.x/docs/validation-annotation.html Admittedly, I used this approach these past few days and found myself back to validations in XML: http://blog.ealden.net/2008/03/working-with-struts-2-validators.html Thanks -- Ealden Esto E. Escañan http://blog.ealden.net - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]