Re: Validation in Struts 1
On Mon, 2010-10-25 at 14:01 -0400, Anjib Mulepati wrote: > ok so is this mean both is server side validation and client side > validation is done with Javascript? > > Also between these two(.xml and execute() method) which one is better? > Any pros and cons? > > Anjib > > On 10/25/2010 1:55 PM, Dave Newton wrote: > > That's not combining client- and server-side validation, that's > > combining declarative and programmatic validation, unless you're > > talking about the JavaScript validation method. > > > > Dave > > > > On Mon, Oct 25, 2010 at 1:52 PM, Anjib Mulepati wrote: > >> Hi > >> > >> Can we combine client side validation and server side validation? i.e. > >> using > >> validation.xml as well as validation in validate() method as well. > >> Does it make any sense? > >> > >> Thanks > >> > > - > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > > > > > > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > Client side validation via javascripts prevents client to server communication if some error can be deal with at client side, ie, input eroor, which reduces server burden. However, server side validation is also needed because clients can walk around client side intentionally. Please correct me if I said something wrong. Qiang -- Qiang Li HuBei Polytechnic Institute No. 17 YuQuan Road XiaoGan HuBei 432100 China E-mail: liqi...@hbvtc.edu.cn - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Validation in Struts 1
On Mon, Oct 25, 2010 at 2:01 PM, Anjib Mulepati wrote: > ok so is this mean both is server side validation and client side validation > is done with Javascript? ??? No. Client-side validation is done with JavaScript, because that's what runs inside browsers. Server-side validation is done in Java, whether or not it's driven by XML. > Also between these two(.xml and execute() method) which one is better? Any > pros and cons? execute() method? Do you mean the validate() method? Neither is better--they're different things. XML/declarative validation is more useful for simple validations: length, masks, etc. The validate() method is more useful for business-logic-oriented validation, like "if a business has a flag set then we only allow US addresses" or something along those lines. The two are combinable; use XML for easy stuff, validate() for hard stuff. Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Validation in Struts 1
ok so is this mean both is server side validation and client side validation is done with Javascript? Also between these two(.xml and execute() method) which one is better? Any pros and cons? Anjib On 10/25/2010 1:55 PM, Dave Newton wrote: That's not combining client- and server-side validation, that's combining declarative and programmatic validation, unless you're talking about the JavaScript validation method. Dave On Mon, Oct 25, 2010 at 1:52 PM, Anjib Mulepati wrote: Hi Can we combine client side validation and server side validation? i.e. using validation.xml as well as validation in validate() method as well. Does it make any sense? Thanks - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Validation in Struts 1
That's not combining client- and server-side validation, that's combining declarative and programmatic validation, unless you're talking about the JavaScript validation method. Dave On Mon, Oct 25, 2010 at 1:52 PM, Anjib Mulepati wrote: > Hi > > Can we combine client side validation and server side validation? i.e. using > validation.xml as well as validation in validate() method as well. > Does it make any sense? > > Thanks > - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: Validation in Struts DisptachAction
Hi Vaneet I'm no expert on this to be sure; but I ran into a similiar issue. What I did was provided the check for the Read only mode in the forms validate method; if read only mode the validate method returned null; otherwise it invoked the super.validate method which performs the normal validation checks on the form. Hope this helps. Reg From: Vaneet Sharma [mailto:[EMAIL PROTECTED] Sent: Thu 24/08/2006 8:08 AM To: struts-user@jakarta.apache.org Subject: Validation in Struts DisptachAction Hii I am using Struts DispatchAction and i am facing a peculiar problem while validating . Now i want to validate ,my action form only in insert or update mode. For read mode i want to prevent validation. To achive this is am writing validation="false" in the action mapping , and i am manually calling validation in insert and update methods of my action class. DynaActionForm frm=(DynaActionForm)form; ActionErrors errors=frm.validate(mapping,request); if ( errors != null && !errors.isEmpty() ) { saveErrors(request, errors); return (mapping.findForward("validationfailure")); } But when i am doing validation in this way. It is always trying to validate the action , even in read mode also. Can anybody tell me why is this happening. Thanx in advance Disclaimer : This message and any attachments (hereinafter referred to as the Said Information) are intended solely for the addressee. The Said Information is confidential and may be privileged and is also prohibited from disclosure. Access, use, copying, distribution or e-use of the Said Information by anyone except the addressee is unauthorized. If you are not the intended addressee, please destroy all copies of the Said Information in your possession and also delete the same from your computer. Any views expressed in the Said Information are those of the individual sender except where the sender, with due authority of CRISIL Ltd./CRISIL MarketWire Ltd./Global Data Services of India Ltd. specifically states them to be the views of CRISIL Ltd./CRISIL MarketWire Ltd./Global Data Services of India Ltd. Nothing contained in the Said Information is capable or intended to create any legally binding obligations on the sender CRISIL Ltd./CRISIL MarketWire Ltd./Global Data Services of India L td. who accept no responsibility, whatsoever, for loss or damage from the use of the Said Information including damage from viruses. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation in Struts DisptachAction
Sharma, If insert, update and read modes, are represented by 3 different submits that trigger the actions, make them 3 different action mappings, then put validate="false" in the read action mapping, and true in the rest. -Original Message- From: Vaneet Sharma [mailto:[EMAIL PROTECTED] Sent: Thursday, August 24, 2006 2:09 PM To: struts-user@jakarta.apache.org Subject: Validation in Struts DisptachAction Hii I am using Struts DispatchAction and i am facing a peculiar problem while validating . Now i want to validate ,my action form only in insert or update mode. For read mode i want to prevent validation. To achive this is am writing validation="false" in the action mapping , and i am manually calling validation in insert and update methods of my action class. DynaActionForm frm=(DynaActionForm)form; ActionErrors errors=frm.validate(mapping,request); if ( errors != null && !errors.isEmpty() ) { saveErrors(request, errors); return (mapping.findForward("validationfailure")); } But when i am doing validation in this way. It is always trying to validate the action , even in read mode also. Can anybody tell me why is this happening. Thanx in advance Disclaimer : This message and any attachments (hereinafter referred to as the Said Information) are intended solely for the addressee. The Said Information is confidential and may be privileged and is also prohibited from disclosure. Access, use, copying, distribution or e-use of the Said Information by anyone except the addressee is unauthorized. If you are not the intended addressee, please destroy all copies of the Said Information in your possession and also delete the same from your computer. Any views expressed in the Said Information are those of the individual sender except where the sender, with due authority of CRISIL Ltd./CRISIL MarketWire Ltd./Global Data Services of India Ltd. specifically states them to be the views of CRISIL Ltd./CRISIL MarketWire Ltd./Global Data Services of India Ltd. Nothing contained in the Said Information is capable or intended to create any legally binding obligations on the sender CRISIL Ltd./CRISIL MarketWire Ltd./Global Data Services of India L td. who accept no responsibility, whatsoever, for loss or damage from the use of the Said Information including damage from viruses. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation in Struts for Required fields
One more: you need something like this in your ApplicationResources: errors.required={0} is required. In article <[EMAIL PROTECTED]>, Caroline Jen <[EMAIL PROTECTED]> wrote: > To add to the list: > > 5. the validator-rules.xml and validation.xml must be > in the AppName/WEB-INF directory. > 6. Make sure that there is a proper version of the > commons-validator.jar file. > 7. there is in > the .jsp to turn on the validation and to show warning > messages in red > 8. validation plug-in in the struts-config.xml; > > -Caroline > --- Erik Weber <[EMAIL PROTECTED]> wrote: > > > Somehow we lost the list on a couple of posts. > > > > OK, so, these are the things I assume you have > > checked so far: > > > > 1) you have an html:select tag with property = > > "reportType", and the > > default option's value is "" > > 2) your ActionForm extends one of the proper types > > (such as > > ValidatorForm) and has the proper getters and > > setters for the reportType > > field > > 3) in struts-config.xml, you have configured the > > action (the same one > > that your form will submit to) with validate = true, > > and you have named > > the proper ActionForm to associate with the action > > (one of your > > form-bean declarations) > > 4) the field name in validation.xml matches the > > field name of your > > select ("reportType"), and the form name in > > validation.xml matches the > > same form name that you are associating with the > > action in > > struts-config.xml (the name of the form configured > > in the action matches > > one of your form-bean declarations) > > > > What else am I leaving out? > > > > Erik - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation in Struts for Required fields
To add to the list: 5. the validator-rules.xml and validation.xml must be in the AppName/WEB-INF directory. 6. Make sure that there is a proper version of the commons-validator.jar file. 7. there is in the .jsp to turn on the validation and to show warning messages in red 8. validation plug-in in the struts-config.xml; -Caroline --- Erik Weber <[EMAIL PROTECTED]> wrote: > Somehow we lost the list on a couple of posts. > > OK, so, these are the things I assume you have > checked so far: > > 1) you have an html:select tag with property = > "reportType", and the > default option's value is "" > 2) your ActionForm extends one of the proper types > (such as > ValidatorForm) and has the proper getters and > setters for the reportType > field > 3) in struts-config.xml, you have configured the > action (the same one > that your form will submit to) with validate = true, > and you have named > the proper ActionForm to associate with the action > (one of your > form-bean declarations) > 4) the field name in validation.xml matches the > field name of your > select ("reportType"), and the form name in > validation.xml matches the > same form name that you are associating with the > action in > struts-config.xml (the name of the form configured > in the action matches > one of your form-bean declarations) > > What else am I leaving out? > > Erik > > > > Priya Jotwani wrote: > > >Yes I have set the validate= "true" in and the > field names are same too > >:( > > > >-Original Message- > >From: Erik Weber [mailto:[EMAIL PROTECTED] > >Sent: Tuesday, October 05, 2004 11:32 PM > >To: Priya Jotwani > >Subject: Re: Validation in Struts for Required > fields > > > >Does the property attribute to html:select have the > same value you have > >specified as the field name in validation.xml > ("reportType", > >"productLine")? Do you have the validate attribute > set to "true" in > >struts-config.xml for the relevant action > configuration? > > > >Erik > > > > > >Priya Jotwani wrote: > > > > > > > >>Hi Erik, > >> > >>I am using html:select tag like below in my JSP > >> > >>Select a Product > Line > >> > >>Thanks, > >>Priya > >> > >>-Original Message- > >>From: Erik Weber [mailto:[EMAIL PROTECTED] > > >>Sent: Tuesday, October 05, 2004 11:04 PM > >>To: Struts Users Mailing List > >>Subject: Re: Validation in Struts for Required > fields > >> > >>In your JSP, where are your selects? Are you using > html:select tags to > >>produce them? > >> > >>Erik > >> > >> > >>Priya Jotwani wrote: > >> > >> > >> > >> > >> > >>>Hi , > >>> > >>> > >>> > >>>I have a JSP Page where I have two dropdowns > displaying default > >>> > >>> > >values. > > > > > >>>Before submitting that page, the user should > select something from > >>> > >>> > >>> > >>> > >>these > >> > >> > >> > >> > >>>two dropdowns and if he doesn't selects, there > should be an error > >>>message displayed on the top saying "This field > is required". > >>> > >>>This is what I am doing but it doesn't gives me > an error message and > >>> > >>> > >am > > > > > >>>able to proceed to the next page. Any idea as to > what could be > >>> > >>> > >possibly > > > > > >>>wrong/missing ? > >>> > >>> > >>> > >>>In my validator.xml , I have > >>> > >>> > >>> > >>> name="ClientReportingForm"> > >>> > >>> > >>> > >>> property="reportType" > >>>depends="required"> > >>> > >>> > >>>key="prompt.reportType"/> > >>> > >>> > >>> > >>> > >>> > >>> property="productLine" > >>>depends="required"> > >>> > >>> key="prompt.productLine"/> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>>In my ApplicationResources.properties I have > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>>And in my JSP Page I have > >>> > >>> > >>> > >>> > > >>> > >>> > >>> > >>> > >>> > === message truncated === ___ Do you Yahoo!? Declare Yourself - Register online to vote today! http://vote.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation in Struts for Required fields
Somehow we lost the list on a couple of posts. OK, so, these are the things I assume you have checked so far: 1) you have an html:select tag with property = "reportType", and the default option's value is "" 2) your ActionForm extends one of the proper types (such as ValidatorForm) and has the proper getters and setters for the reportType field 3) in struts-config.xml, you have configured the action (the same one that your form will submit to) with validate = true, and you have named the proper ActionForm to associate with the action (one of your form-bean declarations) 4) the field name in validation.xml matches the field name of your select ("reportType"), and the form name in validation.xml matches the same form name that you are associating with the action in struts-config.xml (the name of the form configured in the action matches one of your form-bean declarations) What else am I leaving out? Erik Priya Jotwani wrote: Yes I have set the validate= "true" in and the field names are same too :( -Original Message- From: Erik Weber [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 05, 2004 11:32 PM To: Priya Jotwani Subject: Re: Validation in Struts for Required fields Does the property attribute to html:select have the same value you have specified as the field name in validation.xml ("reportType", "productLine")? Do you have the validate attribute set to "true" in struts-config.xml for the relevant action configuration? Erik Priya Jotwani wrote: Hi Erik, I am using html:select tag like below in my JSP Select a Product Line Thanks, Priya -Original Message- From: Erik Weber [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 05, 2004 11:04 PM To: Struts Users Mailing List Subject: Re: Validation in Struts for Required fields In your JSP, where are your selects? Are you using html:select tags to produce them? Erik Priya Jotwani wrote: Hi , I have a JSP Page where I have two dropdowns displaying default values. Before submitting that page, the user should select something from these two dropdowns and if he doesn't selects, there should be an error message displayed on the top saying "This field is required". This is what I am doing but it doesn't gives me an error message and am able to proceed to the next page. Any idea as to what could be possibly wrong/missing ? In my validator.xml , I have In my ApplicationResources.properties I have And in my JSP Page I have /> Thanks, Priya - 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: Validation in Struts for Required fields
In your JSP, where are your selects? Are you using html:select tags to produce them? Erik Priya Jotwani wrote: Hi , I have a JSP Page where I have two dropdowns displaying default values. Before submitting that page, the user should select something from these two dropdowns and if he doesn't selects, there should be an error message displayed on the top saying "This field is required". This is what I am doing but it doesn't gives me an error message and am able to proceed to the next page. Any idea as to what could be possibly wrong/missing ? In my validator.xml , I have In my ApplicationResources.properties I have And in my JSP Page I have /> Thanks, Priya - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation in Struts
In your ActionForm, add the validation to the validate method. For example, you would have something like this: public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if ((person == null) || (person.length() < 1)) errors.add("person", new ActionError("ch03.hello.no.person.error")); return errors; } where 'person' is the name of the select box field. On Sat, 18 Sep 2004 21:41:49 +0530, Priya Jotwani <[EMAIL PROTECTED]> wrote: > Hi, > > I have a page where a user should select something from the dropdown > before clicking on Submit. If he doesn't selects anything, an > errorMessage should get displayed on the same page saying ' Please > select an option ' > > How can I do such validations in Struts. > > Thanks in Advance, > > Priya > > -- ... Rogue Chameleon ... - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation in Struts
Priya, Use the "required" validator rule and be sure to use the html:javascript tag in your JSP to have the client-side Javascript embedded in the page given out to the user. See the first validator, "required", at the below URL: http://struts.apache.org/userGuide/dev_validator.html#builtin Regards, David -Original Message- From: Priya Jotwani [mailto:[EMAIL PROTECTED] Sent: Saturday, September 18, 2004 12:12 PM To: Struts Users Mailing List Subject: Validation in Struts Hi, I have a page where a user should select something from the dropdown before clicking on Submit. If he doesn't selects anything, an errorMessage should get displayed on the same page saying ' Please select an option ' How can I do such validations in Struts. Thanks in Advance, Priya - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation in struts
Divya, if your problem is just to display an error message box instead of the message. use the tag inside validator-rules.xml for your validation and map it with appropriate message key that you want to display. :) Jitender Kumar C.V.
RE: Validation in struts
Hi Jitender, I guess it is "import org.apache.struts.validator.ValidatorForm" I have extended this as well. What should be done to show an error message box instead of showing it on top of the page ? I am sure I am missing something :) Thanks, Divya. -Original Message- From: Jitender K Chukkavenkata [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 6:40 PM To: Struts Users Mailing List Subject: RE: Validation in struts Hi Divya, I think you need to extend your form class with org.apache.struts.validator.action.ValidatorForm or ValidatorActionFrom instead of org.apache.struts.action.ActionForm. have u done it? Regards, Jitender. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation in struts
Hi Divya, I think you need to extend your form class with org.apache.struts.validator.action.ValidatorForm or ValidatorActionFrom instead of org.apache.struts.action.ActionForm. have u done it? Regards, Jitender.
RE: Validation in struts
Hi Jitendar, Thanks for your help. I am using the validator framework now and I see that when I click the "submit" button, it does the validation and comes back with the error message on top of the page but does not pop-up a messagebox. I would want to prompt for a message box if, say a particular mandatory field is missed. - Now, I am using also after the tag. - edited validation.xml to have the field names. - included the validator plugin in my struts-config.xml - included errors.required in my application properties file. - included onsubmit function in my html:form to point to validate(this) Is there something else that I am missing ? Thanks, Divya. -Original Message- From: Jitender K Chukkavenkata [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 9:51 AM To: Struts Users Mailing List Subject: Re: Validation in struts U can use struts validations framework as well go thru struts validation framework.. Jitender Kumar C.V. IBM Global Services India (Pvt.) Ltd., Embassy Golf Links Business Park, Block C, Bangalore - 560 071. Phone : + 91 (80) 51056320 Mobile: + 91 9886219429 Location : EGC-3*-058. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Validation in struts
hi Divya, For doing clinet side validation you will have to configure validation framework and write ur own custom validation in that xml file or use the basic validation provided by that framework. In the jsp page you will have to put one struts javascipt tag. This tag will actually get all the custom java script for that page and thus client side validation java script will b put in jsp file. sachin xoriant, mumbai -Original Message- From: Divya B Sridhar [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 9:51 AM To: [EMAIL PROTECTED] Subject: Validation in struts Hi All, It is said that the validation(client side validations like say a particular textbox field can contain numbers only etc) should not be explicitly written in client-side validation javascripts in a struts framework. How can such things be accomplished using struts without writing specific client-side validation javascripts functions on the jsp page? Any help is greatly appreciated. Thanks, Divya.
RE: Validation in struts
Greg, Thanks for your response. Is this validator framework supported for struts 1.1 since I use struts 1.1 for my application. Thanks, Divya. -Original Message- From: Greg Ludington [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 15, 2004 10:11 AM To: Struts Users Mailing List Subject: Re: Validation in struts > It is said that the validation(client side validations like say a > particular textbox field can contain numbers only etc) should not be > explicitly written in client-side validation javascripts in a struts > framework. How can such things be accomplished using struts without > writing specific client-side validation javascripts functions on the > jsp page? Any help is greatly appreciated. You will want to read up on the Validator framework. When you use the Validator, you configure rules about your form in an XML file. Struts will use those rules to perform server-side validation, but, for many basic types of validation, Struts can also (optionally) emit the proper javascript for client-side validation. You can still write your own javascript, if you need to or want to, but for many validation tasks -- including the "can contains numbers only" scenario you mentioned -- Struts will do it for you. You can find a HOWTO guide on the Validator on the Struts site here: http://struts.apache.org/userGuide/dev_validator.html Also, I believe the Struts distribution ships with a validator example. -Greg - 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: Validation in struts
> It is said that the validation(client side validations like say a particular > textbox field can contain numbers only etc) should not be explicitly written > in client-side validation javascripts in a struts framework. How can such > things be accomplished using struts without writing specific client-side > validation javascripts functions on the jsp page? > Any help is greatly appreciated. You will want to read up on the Validator framework. When you use the Validator, you configure rules about your form in an XML file. Struts will use those rules to perform server-side validation, but, for many basic types of validation, Struts can also (optionally) emit the proper javascript for client-side validation. You can still write your own javascript, if you need to or want to, but for many validation tasks -- including the "can contains numbers only" scenario you mentioned -- Struts will do it for you. You can find a HOWTO guide on the Validator on the Struts site here: http://struts.apache.org/userGuide/dev_validator.html Also, I believe the Struts distribution ships with a validator example. -Greg - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Validation in struts
U can use struts validations framework as well go thru struts validation framework.. Jitender Kumar C.V. IBM Global Services India (Pvt.) Ltd., Embassy Golf Links Business Park, Block C, Bangalore - 560 071. Phone : + 91 (80) 51056320 Mobile: + 91 9886219429 Location : EGC-3*-058.