-----Original Message----- From: James Pan [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 23, 2003 2:12 PM To: [EMAIL PROTECTED] Subject: [OS-webwork] Using action beans in if-test
Hi, I'm really new with WebWork, so please bear with me. I'm trying to create a log-in page (simple username/password form) that posts to an action which, through some chain of logic, verifies the username/password combo... if the log-in fails, i want to return to the original log-in page with an error message... how do I put a test in the if-tag for a method of the action bean? -------------- lots 'o code deleted -------------- WebWork handles errors for you, so if you have field error (see setUsername()) or a lookup error (see doExecute()) errors are added to WebWork's Value Stack. You can then dig out the errors in the JSP page (see the test for "hasErrorMessages") If you use WebWork's ui textfield and password tags (along with a collection of ui templates in template/standard) errors you add in the Login class are automatically added to the view. Hope this gets ya going! Rossi Here is my simple setup: --> My index page: <jsp:forward page="login!default.action" /> --> In views.properties: # General actions. login.action=common.Login login.input=login.jsp login.success=success.jsp login.error=login.jsp --> My Login class (note that it extends WebWork's ActionSupport class): public class Login extends ActionSupport implements CommandDriven { private String username = ""; private String password = ""; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { if (username.trim().equals("")) { throw new IllegalArgumentException("Please specify your user name."); } this.username = username; } protected String doExecute() throws Exception { User user = new UserMapper().find(getUsername(), getPassword()); if (user == null) { addErrorMessage("The username and password combination are invalid. " + "Make sure the Caps Lock key has not been accidentally turned on."); return ERROR; } ActionContext.getSession().put("user", user); return SUCCESS; } } --> My login.jsp: <%@ taglib uri="webwork" prefix="webwork" %> <%@ taglib uri="webwork" prefix="ui" %> <link rel="stylesheet" type="text/css" href="template/standard/styles.css" title="Style"> <html> <head> <title>Login to My System</title> </head> <body onLoad="document.login.username.focus()"> <center> <h2><i>Login to My System</i></h2> <table> <tr><td> <form name="login" action="login.action" method="POST"> <table> <ui:textfield label="text('login.username.label')" name="'username'" /> <ui:password label="text('login.password.label')" name="'password'" /> <tr><td colspan="2" align="center"><hr></td></tr> <tr><td colspan="2" align="center"> <input type="submit" value="Login"/> </td></tr> </table> </form> </td></tr> </table> <webwork:if test="hasErrorMessages == true"> <br><br> <webwork:iterator value="errorMessages"> <font color="red"><webwork:property/></font><br> </webwork:iterator> </webwork:if> </center> </body> </html> ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork