You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Session A Mwamufiya <sm...@andrew.cmu.edu> on 2007/08/06 16:00:53 UTC

Defining a validate() method

Hi,

I want to set up my own validate method to validate fields in my own way, but I'm not sure how to set up the method.  I don't know how to set or clear the validation error message.  Is it ok just to use the action's error stack, like this:

public void validate() {
  if (listOfExistingElement.contains(field1)) {
    addActionError("This element already exists");
  }
}

Is there a better way to make use of the framework, or is this it?  I searched for examples online but couldn't find any.

Thanks for the push,
Session


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Defining a validate() method

Posted by Session A Mwamufiya <sm...@andrew.cmu.edu>.
Great help,

Thanks!
Session


> I forgot to add that you can also use annotations or XML validation for
> simple validations.  If you set the validate=true on your s:form and you
> are using the XML validators, it will generate the client side javascript
> nessessary to do the validations.  After the form submits it will do those
> validation again on the server side and if you have any additional
> validation to do that is not covered by a validator you can add the
> validation cod to your action.
> 
> I have tried to write my own validator recently but I got stuck and 
> because of a time constraint I did my validations in my action with 
> addFieldError.  I would like to see more information on writing validators
> and how a include the javascript to generate for that validator
> 
> On 8/6/07, Richard Sayre <ri...@gmail.com> wrote:
>> addFieldError("fieldName","message");  will add a specific field error.
>> If you are using the XHTML theme, the error will appear above the field.
>> 
>> 
>> This should set and clear the validation message for you.  If you are 
>> using the simple theme you have to add the s:fielderror tag.
>> 
>> 
>> On 8/6/07, Session A Mwamufiya <sm...@andrew.cmu.edu> wrote:
>>> Hi,
>>> 
>>> I want to set up my own validate method to validate fields in my own
>>> way, but I'm not sure how to set up the method.  I don't know how to
>>> set or clear the validation error message.  Is it ok just to use the
>>> action's error stack, like this:
>>> 
>>> public void validate() { if (listOfExistingElement.contains(field1)) {
>>>  addActionError("This element already exists"); } }
>>> 
>>> Is there a better way to make use of the framework, or is this it?  I
>>> searched for examples online but couldn't find any.
>>> 
>>> Thanks for the push, Session
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>>  To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For
>>> additional commands, e-mail: user-help@struts.apache.org
>>> 
>>> 
>> 
> 
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional
> commands, e-mail: user-help@struts.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Defining a validate() method

Posted by Richard Sayre <ri...@gmail.com>.
I forgot to add that you can also use annotations or XML validation
for simple validations.  If you set the validate=true on your s:form
and you are using the XML validators, it will generate the client side
javascript nessessary to do the validations.  After the form submits
it will do those validation again on the server side and if you have
any additional validation to do that is not covered by a validator you
can add the validation cod to your action.

I have tried to write my own validator recently but I got stuck and
because of a time constraint I did my validations in my action with
addFieldError.  I would like to see more information on writing
validators and how a include the javascript to generate for that
validator

On 8/6/07, Richard Sayre <ri...@gmail.com> wrote:
> addFieldError("fieldName","message");  will add a specific field
> error.  If you are using the XHTML theme, the error will appear above
> the field.
>
> This should set and clear the validation message for you.  If you are
> using the simple theme you have to add the s:fielderror tag.
>
>
> On 8/6/07, Session A Mwamufiya <sm...@andrew.cmu.edu> wrote:
> > Hi,
> >
> > I want to set up my own validate method to validate fields in my own way, but I'm not sure how to set up the method.  I don't know how to set or clear the validation error message.  Is it ok just to use the action's error stack, like this:
> >
> > public void validate() {
> >   if (listOfExistingElement.contains(field1)) {
> >     addActionError("This element already exists");
> >   }
> > }
> >
> > Is there a better way to make use of the framework, or is this it?  I searched for examples online but couldn't find any.
> >
> > Thanks for the push,
> > Session
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Defining a validate() method

Posted by Richard Sayre <ri...@gmail.com>.
addFieldError("fieldName","message");  will add a specific field
error.  If you are using the XHTML theme, the error will appear above
the field.

This should set and clear the validation message for you.  If you are
using the simple theme you have to add the s:fielderror tag.


On 8/6/07, Session A Mwamufiya <sm...@andrew.cmu.edu> wrote:
> Hi,
>
> I want to set up my own validate method to validate fields in my own way, but I'm not sure how to set up the method.  I don't know how to set or clear the validation error message.  Is it ok just to use the action's error stack, like this:
>
> public void validate() {
>   if (listOfExistingElement.contains(field1)) {
>     addActionError("This element already exists");
>   }
> }
>
> Is there a better way to make use of the framework, or is this it?  I searched for examples online but couldn't find any.
>
> Thanks for the push,
> Session
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org