Re: validation question
oh I found that my implementation will let user skip my validation and directly execute the action. - Original Message - From: "Justy Wong" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Tuesday, October 19, 2004 1:48 PM Subject: Re: validation question > Thanks!!! I tried your last suggestion and it works fine!!! > > public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest > httpServletRequest) { > if (getCheck()==null) { > return null; > } else { > return super.validate(actionMapping, httpServletRequest); > } > } > > > > - Original Message - > From: "Joe Hertz" <[EMAIL PROTECTED]> > To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> > Sent: Tuesday, October 19, 2004 11:43 AM > Subject: RE: validation question > > > > > Joe, do u mean checking the field with "validwhen" using > > > validation.xml or > > > implement the actionForm.validate() ? > > > I really want to use the basic struts validation framework instead of > > > implementing validate() function to minimize the maintainence cost. > > > > > > You can do it both ways. > > > > Use validation.xml, but ALSO define your own validate() that checks the > > "should I validate property". > > > > All you have to do to get the validation framework to do it's thing is to > > call super.vallidate() in your own validate() method. > > > > -Some Other Joe > > > > > > > > - > > 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: validation question
Thanks!!! I tried your last suggestion and it works fine!!! public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) { if (getCheck()==null) { return null; } else { return super.validate(actionMapping, httpServletRequest); } } - Original Message - From: "Joe Hertz" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> Sent: Tuesday, October 19, 2004 11:43 AM Subject: RE: validation question > > Joe, do u mean checking the field with "validwhen" using > > validation.xml or > > implement the actionForm.validate() ? > > I really want to use the basic struts validation framework instead of > > implementing validate() function to minimize the maintainence cost. > > > You can do it both ways. > > Use validation.xml, but ALSO define your own validate() that checks the > "should I validate property". > > All you have to do to get the validation framework to do it's thing is to > call super.vallidate() in your own validate() method. > > -Some Other Joe > > > > - > 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 question
Thanks for all!! >From Joe: > > On the other hand, if you actually have this situation, you don't have to > > turn off validation -- simply implement your validation rules so that they > > can recognize the distinction. For example, have all your forms submit a > > hidden field, and have your validation method only evaluate its validation > > rules if that field has a defined value. When the page is retrieved > > without a form submission, this value is not going to be defined. Joe, do u mean checking the field with "validwhen" using validation.xml or implement the actionForm.validate() ? I really want to use the basic struts validation framework instead of implementing validate() function to minimize the maintainence cost. >From Eddie: > Nope. Perhaps in time the Validation framework will evolve to be smart > enough that it "knows" (or can) that it doesn't need to validate the form on > the first display. I'm actually kind of surprised this behavior hasn't been > added in by now. Seems it would be simple enough to do, but, perhaps I'm > oversimplifying in my head. Thanks for your answer!! that means I've no other choices apart from changing my program - Original Message - From: "Eddie Bush" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Tuesday, October 19, 2004 10:53 AM Subject: Re: validation question > Nice trick, Joe - hadn't thought of doing that :-) > > - Original Message - > From: "Joe Germuska" <[EMAIL PROTECTED]> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]> > Sent: Monday, October 18, 2004 9:40 PM > Subject: Re: validation question > > > > At 10:28 AM +0800 10/19/04, Justy Wong wrote: > >>Thx for your suggestions. > >> > >>> 1) 2 action mappings -- 1 with validation turned off (welcome.do) and 1 > >>with it on (login.do). > >> > >>that means for every action, I've to create 1 more action. but it will > >>almost double the maintainence affort. > > > > In practice, it's rare that you actually have a webapp where every single > > page is sometimes accessed as the result of a form submission and > > sometimes as a simple HTTP GET. And especially unlikely that you would > > have this to the scope where the actual dual maintenance is a serious > > burden. At least, in my experience, this is simply "the right way to do > > it." > > > > On the other hand, if you actually have this situation, you don't have to > > turn off validation -- simply implement your validation rules so that they > > can recognize the distinction. For example, have all your forms submit a > > hidden field, and have your validation method only evaluate its validation > > rules if that field has a defined value. When the page is retrieved > > without a form submission, this value is not going to be defined. > > > > Remember that you can implement the "validate()" method of your > > ActionForms anyway you like. > > > > Joe > > > > -- > > Joe Germuska[EMAIL PROTECTED] http://blog.germuska.com "In > > fact, when I die, if I don't hear 'A Love Supreme,' I'll turn back; I'll > > know I'm in the wrong place." > >- Carlos Santana > > > > - > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > --- > avast! Antivirus: Outbound message clean. > Virus Database (VPS): 0442-3, 10/15/2004 > Tested on: 10/18/2004 9:53:40 PM > avast! - copyright (c) 2000-2004 ALWIL Software. > http://www.avast.com > > > > > - > 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 question
Thx for your suggestions. > 1) 2 action mappings -- 1 with validation turned off (welcome.do) and 1 with it on (login.do). that means for every action, I've to create 1 more action. but it will almost double the maintainence affort. > 2) Turn validation off, and handle that in the action: then I've to give up struts validation framework I think these 2 suggestions are simple workaround for this problem, however, it will break the framework in some degree Is there any other solutions come with Struts?? Thanks! Justy - Original Message - From: "Durham David R Jr Contr 805 CSPTS/SCE" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Sent: Tuesday, October 19, 2004 1:23 AM Subject: RE: validation question > > The validation works fine however, when I just type the > http://localhost:8080/login.do > > in my browser (no submit), the validation error will show up at once. > > I understand that it's just like I submit a form to login.do action > without any > > parameter. My question is, do struts provide any simple method to > avoid this and just > > show no error message? > > There's a few different ways to handle this problem. > > 1) 2 action mappings -- 1 with validation turned off (welcome.do) and 1 > with it on (login.do). > > 2) Turn validation off, and handle that in the action: > > login.do > > if (isSubmitted) { > errors = form.validate() > // redirect or do other authenticate work > } else { > return mapping.findForward("login"); > } > > HTH, > > Dave > > > - > 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]
validation question
Hi, I have a http://localhost:8080/login.do action and I want to do validation for the form when user submit their username & password. here is my setting in validation.xml: mask ^[0-9a-zA-Z]*$ The validation works fine however, when I just type the http://localhost:8080/login.do in my browser (no submit), the validation error will show up at once. I understand that it's just like I submit a form to login.do action without any parameter. My question is, do struts provide any simple method to avoid this and just show no error message? Thanks a lot!!! Justy