[ 
https://issues.apache.org/struts/browse/WW-1884?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40921
 ] 

Caine Lai commented on WW-1884:
-------------------------------

I have the exact same issue here.  I'm not using a struts.xml file.  All my 
configuration is done via annotations.  Here is an action that has the issue 
mentioned above:

@Results({
    @Result(name=Action.SUCCESS, value=ACTION_HOME, 
type=ServletActionRedirectResult.class),
    @Result(name=Action.INPUT, value=VIEW_LOGIN, type=FreemarkerResult.class)
})
@Validation()
public class LoginAction extends ActionSupport implements Preparable, 
ServletRequestAware {
                
        private static final long serialVersionUID = 1L;
        
        private final Logger log = Logger.getLogger(getClass());
                                                
    public String execute() throws Exception {
    
        InitialContext initialContext = new InitialContext();
                        
        UserServiceLocal userService = (UserServiceLocal) 
                initialContext.lookup(JNDI_NAME_LOCAL_USER_SERVICE);
        
        User user = null;
        try {
                log.debug("Checking login for user: " + getUsername());
                user = userService.login(getUsername(), getPassword());
        }
        catch (UserNotFoundException ex) {
                log.debug("Invalid username: " + getUsername() + " -> " + ex);
                addActionError(getText("i18n.login.invalidUsername"));
                return INPUT; 
        }
        catch (InvalidPasswordException ex) {
                log.debug("Invalid password for user: " + getUsername() + " -> 
" + ex);
                addActionError(getText("i18n.login.invalidPassword"));
                return INPUT; 
        }
        // Successful login.  Store the user object in the session.
        HttpSession session = this.servletRequest.getSession();
        session.setAttribute(LOGGED_IN_USER_SESSION_ATTRIBUTE, user);
        
        log.debug("Successful login for user: " + getUsername());
        return SUCCESS;
    }
    
    public void prepare() {
        this.username = "[EMAIL PROTECTED]";
    }
        
    public void setServletRequest(HttpServletRequest request) {
        this.servletRequest = request;
    }
    
    private HttpServletRequest servletRequest;
    public HttpServletRequest getServletRequest() {
        return servletRequest;
    }
            
    private String username;    
    public String getUsername() {
        return username;
    }   
    
    @RequiredStringValidator(message = "Username is required.", key = 
"i18n.validation.username", shortCircuit = true, trim = true)
    @StringLengthFieldValidator(message = "You exceeded the max character 
limit.", key = "i18n.validation.fieldTooLong", shortCircuit = true, trim = 
true, minLength = "1",  maxLength = "255")
    public void setUsername(String username) {
        this.username = username;
    }

    private String password;    
    public String getPassword() {
        return password;
    } 
    
    @RequiredStringValidator(message = "Password is required.", key = 
"i18n.validation.password", shortCircuit = true, trim = true)
    @StringLengthFieldValidator(message = "You exceeded the max character 
limit.", key = "i18n.validation.fieldTooLong", shortCircuit = true, trim = 
true, minLength = "1",  maxLength = "50")
    public void setPassword(String password) {
        this.password = password;
    }
}

By the way, here is a discussion on the OpenSymphony boards regarding this 
issue:  http://forums.opensymphony.com/thread.jspa?messageID=139232

> Validator Randomly Fails Valid Input
> ------------------------------------
>
>                 Key: WW-1884
>                 URL: https://issues.apache.org/struts/browse/WW-1884
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Actions, Interceptors
>    Affects Versions: 2.0.6
>         Environment: java version "1.6.0"
> Java(TM) SE Runtime Environment (build 1.6.0-b105)
> Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
> struts2-core-2.0.6.jar
> struts2-tiles-plugin-2.0.6.jar
> xwork-2.0.1.jar
>            Reporter: Zach
>         Assigned To: Rainer Hermanns
>             Fix For: 2.0.8
>
>
> On occasion, I'm receiving validation failures on valid input.  Struts 
> redirects to the form page and set's invalid input messages.  I'm using only 
> the required strings validations:
>       @Validations(
>                       requiredStrings = {
>                                       @RequiredStringValidator(type = 
> ValidatorType.SIMPLE, fieldName = "req", message = "msg", shortCircuit = 
> true, trim = true)
>                       }
>       )
> I think the error is caused by an exception:
> Apr 15, 2007 10:08:49 AM com.opensymphony.xwork2.util.OgnlUtil 
> internalSetProperty
> WARNING: Caught OgnlException while setting property 'methodName' on type 
> 'com.opensymphony.xwork2.validator.validators.RequiredStringValidator'.
> ognl.NoSuchPropertyException: 
> com.opensymphony.xwork2.validator.validators.RequiredStringValidator.methodName
>       at 
> ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:132)
>       at 
> com.opensymphony.xwork2.util.OgnlValueStack$ObjectAccessor.setProperty(OgnlValueStack.java:68)
>       at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1656)
>       at ognl.ASTProperty.setValueBody(ASTProperty.java:101)
>       at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
>       at ognl.SimpleNode.setValue(SimpleNode.java:246)
>       ...
> I would be willing to bet this has already been logged, and probably fixed, 
> but I can't find a bug logged in this system that says it has.  I also tried 
> to build the latest trunk this morning, but maven reported 11 Test errors and 
> would not complete the build.  I apologize if the fix is already out there, 
> but I'm logging this in case this is a new 2.0.6 issue.  

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to