You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Guilherme <ja...@gmail.com> on 2007/10/06 03:12:26 UTC

Using annotations

Hi,

I'm trying to use annotations to validate some fields in my application. The
code is this:

@Validation
public class Teste extends ActionSupport {

    private Cliente cliente;

    @VisitorFieldValidator(message = "")
    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    @Override
    @SkipValidation
    public String execute() throws Exception {
        // TODO Auto-generated method stub
        return super.execute();
    }
}

@Validation
@Entity
@Table(name="cliente")
@SequenceGenerator(name = "sqc_cliente", sequenceName = "sqc_cliente")
public class Cliente {

...

    @EmailValidator(message = "dfdfdf")
    public String getBairro() {
        return bairro;
    }

...

}

<s:form action="teste.do" method="POST">
    <s:textfield name="cliente.email" label="E-mail" />
    <s:submit value="Enviar" />
</s:form>

These is my configurations do validate data using annotations support.
Something is wrong because the form is not validated.

Someone can help me to solve this problem ?

Thanks.

-- 
Att
Guilherme Mello do Nascimento [http://guilhermemello.com]
PortalJava.com - A maior comunidade Java do Brasil

Re: Using annotations

Posted by Zarar Siddiqi <za...@gmail.com>.
Well, a couple things pop into one's mind:

1. Why are you using the @SkipValidation on the execute() method, this
is telling Struts NOT to validate calls to this action.
2. Your action is called teste.do which is a little fishy because
usually the extension (.do) doesn't need to be specified in the Struts
tags, it finds that on its own (and it's usually .action for Struts 2,
not .do but I guess you might have changed the defaults in
struts.properties)
3. You haven't posted your action definition from struts.xml so I'm
assuming you haven't changed it to somehow exclude the validation
interceptor.

Zarar



On 10/5/07, Guilherme <ja...@gmail.com> wrote:
> Hi,
>
> I'm trying to use annotations to validate some fields in my application. The
> code is this:
>
> @Validation
> public class Teste extends ActionSupport {
>
>     private Cliente cliente;
>
>     @VisitorFieldValidator(message = "")
>     public Cliente getCliente() {
>         return cliente;
>     }
>
>     public void setCliente(Cliente cliente) {
>         this.cliente = cliente;
>     }
>
>     @Override
>     @SkipValidation
>     public String execute() throws Exception {
>         // TODO Auto-generated method stub
>         return super.execute();
>     }
> }
>
> @Validation
> @Entity
> @Table(name="cliente")
> @SequenceGenerator(name = "sqc_cliente", sequenceName = "sqc_cliente")
> public class Cliente {
>
> ...
>
>     @EmailValidator(message = "dfdfdf")
>     public String getBairro() {
>         return bairro;
>     }
>
> ...
>
> }
>
> <s:form action="teste.do" method="POST">
>     <s:textfield name="cliente.email" label="E-mail" />
>     <s:submit value="Enviar" />
> </s:form>
>
> These is my configurations do validate data using annotations support.
> Something is wrong because the form is not validated.
>
> Someone can help me to solve this problem ?
>
> Thanks.
>
> --
> Att
> Guilherme Mello do Nascimento [http://guilhermemello.com]
> PortalJava.com - A maior comunidade Java do Brasil
>

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