I've set up a login page for my site, and I've used the ValidationAware interface on LoginAction in order to display errors on the login form when the user name or password is incorrect. However, this has one unintended result: the first time the user navigates to "server.com/webapp/login.action", the page already displays errors for missing fields.
Is there a way to prevent the validation from firing unless the user is coming back to it after attempting to log in? My first thought is to have another action defined in struts.xml, whose result would just be a redirect to login.jsp, but it seems like there should be a solution that doesn't introduce extra actions into the config. (In general, it's a personal preference to keep XML files as small and simple as possible.) Thanks, ~Dan Allen struts.xml excerpt: <action name="login" class="loginAction"> <!-- class is instantiated by Spring, hence no qualified classname --> <result name="input">/jsp/login.jsp</result> <result name="success">/jsp/redirect.jsp</result> </action> LoginAction.java @SuppressWarnings("unchecked") public class LoginAction extends ActionSupport implements ValidationAware, Validateable, SessionAware { private String userName = null; private String password = null; private String redirectDesintation = null; public LoginChecker loginChecker = null; private Map sessionAttributes = null; @RequiredStringValidator(message="A valid user name is required to log in.") public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return this.userName; } @RequiredStringValidator(message="You must enter your password to log in.") public void setPassword(String password) { this.password = password; } public String getPassword() { return this.password; } // For Spring to provide us with the appropriate implementation. public void setLoginChecker(LoginChecker checker) { this.loginChecker = checker; } @Override public void setSession(Map sessionAttributes) { this.sessionAttributes = sessionAttributes; } public String execute() { // If we made it past the validation, then there's really nothing else to do except // send the user on to wherever s/he was going, via the JSP. // If we don't know where s/he was going, default to the index. if(redirectDesintation == null || redirectDesintation.equals("")) redirectDesintation = "index.action"; return SUCCESS; } @Override public void validate() { User result = loginChecker.checkLogin(userName, password); // If log-in failed, add the action error if(result == null) { addActionError("The submitted user name and password combination was invalid."); } // If it succeeded, set the User object in the session. else { sessionAttributes.put(MidasUtils.USER_IN_SESSION, result); } } } -- This message may contain confidential, proprietary, or legally privileged information. No confidentiality or privilege is waived by any transmission to an unintended recipient. If you are not an intended recipient, please notify the sender and delete this message immediately. Any views expressed in this message are those of the sender, not those of any entity within the KBC Financial Products group of companies (together referred to as "KBC FP"). This message does not create any obligation, contractual or otherwise, on the part of KBC FP. It is not an offer (or solicitation of an offer) of, or a recommendation to buy or sell, any financial product. Any prices or other values included in this message are indicative only, and do not necessarily represent current market prices, prices at which KBC FP would enter into a transaction, or prices at which similar transactions may be carried on KBC FP's own books. The information contained in this message is provided "as is", without representations or warranties, express or implied, of any kind. Past performance is not indicative of future returns. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]