Hi Pierre,

Thanks for your code.
Yes I did get it working with annotation, phew!

Nicole

-----Original Message-----
From: Pierrot52 [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 16 July 2008 9:48 PM
To: user@struts.apache.org
Subject: Re: struts2 validation


Hi Nicole,

This is an action class that does validation of two parameters:

public class SignonAction extends ActionSupport {
    private String username;
    private String password;

    @Override
    public String execute() throws Exception {
        Map session = null;
        boolean authenticated = false;
        try {
            authenticated = Utils.authenticate(username,password);
        } catch(Exception e) {
            // Swallow the exception
        }
        if (authenticated) {
            session = ActionContext.getContext().getSession();
            User user = new User();
            user.setLogin(username);
            user.setEmail("set your email");
            session.put("loggedIn", user);
            return SUCCESS;
        } else {
            return ERROR;
        }
    }

    @RequiredStringValidator(message="", key = "username.required")
    @StringLengthFieldValidator(message = "", key =
"username.invalidLength", minLength = "6" , maxLength = "15")
    @RegexFieldValidator(message = "", key = "prompt.invalidCharacters",
expression = "^[a-zA-Z0-9]+$")
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @RequiredStringValidator(message="", key="password.required")
    @StringLengthFieldValidator(message = "", key =
"password.invalidLength", minLength = "6" , maxLength = "15")
    @RegexFieldValidator(message = "", key = "prompt.invalidCharacters",
expression = "^[a-zA-Z0-9]+$")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}

It uses annotation to validate.

Hope this will help.

Regards.

Pierre


Nicole Luneburg wrote:
>
> Hi all!
>
> Been looking all over the net but my validation simply isn't working :(
>
>
>
> I have a JSP page with a dropdown box in a form.
>
> I just want to make sure the value in the dropdown box is not empty.
>
> It currently looks like this:
>
>
>
> <s:form action=3D"myaction" method=3D"post" validate=3D"true">
>
>         <s:actionerror />
>
>         <s:fielderror />
>
>
>
>         <s:select name=3D"fieldName"
>
>                 id=3D"fieldName"
>
>                 theme=3D"simple"
>
>                 size=3D"1"
>
>                 list=3D"fieldList"
>
>                 headerKey=3D""
>
>                 headerValue=3D"- - Please Select - -"/>
>
>         <s:submit name=3D"Submit"/>
>
> </s:form>
>
>
>
> My setup is that I have an Action class, which uses a Form to set and get
> f= ield values from the JSP page.
>
> In Struts1 I was using the validate(...) method in the Form class.
>
> It seems none of the Struts2 validation examples on the net are working
> for=  me.
>
> Or I'm not doing it right.
>
>
>
> Anyone any ideas how I can do this simply?
>
>
>
> Cheers!
>
> nic
>
>
> ________________________________
> The contents of this email are confidential and may be subject to legal or
> professional privilege and copyright. No representation is made that this
> email is free of viruses or other defects. If you have received this
> communication in error, you may not copy or distribute any part of it or
> otherwise disclose its contents to anyone. Please advise the sender of
> your incorrect receipt of this correspondence.
>
>

--
View this message in context: 
http://www.nabble.com/struts2-validation-tp18438182p18485869.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


The contents of this email are confidential and may be subject to legal or 
professional privilege and copyright. No representation is made that this email 
is free of viruses or other defects. If you have received this communication in 
error, you may not copy or distribute any part of it or otherwise disclose its 
contents to anyone. Please advise the sender of your incorrect receipt of this 
correspondence.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to