You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Priya Jotwani <Pr...@infosys.com> on 2004/09/18 18:11:49 UTC

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


Re: Validation in Struts

Posted by Rogue Chameleon <ro...@gmail.com>.
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
<pr...@infosys.com> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Validation in Struts

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
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:Priya_Jotwani@infosys.com]
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org