craigmcc 2004/08/07 20:28:35 Modified: contrib/struts-faces build.xml contrib/struts-faces/src/conf struts-faces.xml contrib/struts-faces/src/java/org/apache/struts/faces/application ViewHandlerImpl.java contrib/struts-faces/src/java/org/apache/struts/faces/component ErrorsComponent.java contrib/struts-faces/src/java/org/apache/struts/faces/renderer ErrorsRenderer.java contrib/struts-faces/src/java/org/apache/struts/faces/taglib ErrorsTag.java contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient AbstractTestCase.java SimpleTestCase.java contrib/struts-faces/src/systest/org/apache/struts/faces/systest ApplicationResources.properties contrib/struts-faces/web/systest/WEB-INF struts-config.xml Added: contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient LogonTestCase.java contrib/struts-faces/src/systest/org/apache/struts/faces/systest LogonAction.java contrib/struts-faces/web/systest logon.jsp logon1.jsp contrib/struts-faces/web/systest/WEB-INF validation.xml Log: Add more system integration tests for the Struts-Faces Integration Library; particularly one that exercises form submits and the validator framework. FIXME: I'm missing something stupid in my validator setup, because the error messages in LogonTestCase.testIncorrect() do not include the prompt strings as they really should. Revision Changes Path 1.17 +0 -8 jakarta-struts/contrib/struts-faces/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/build.xml,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- build.xml 7 Aug 2004 04:53:34 -0000 1.16 +++ build.xml 8 Aug 2004 03:28:34 -0000 1.17 @@ -504,19 +504,11 @@ </copy> <!-- Copy required configuration files --> -<!-- - <copy todir="${build.home}/webapps/systest/WEB-INF"> - <fileset dir="${build.home}/conf"> - <include name="*.tld"/> - </fileset> - </copy> <copy todir="${build.home}/webapps/systest/WEB-INF"> <fileset dir="${struts.home}/lib"> - <include name="*.tld"/> <include name="valid*.xml"/> </fileset> </copy> ---> <!-- Copy required library JAR files --> <mkdir dir="${build.home}/webapps/systest/WEB-INF/lib"/> 1.10 +10 -0 jakarta-struts/contrib/struts-faces/src/conf/struts-faces.xml Index: struts-faces.xml =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/conf/struts-faces.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- struts-faces.xml 7 Aug 2004 04:53:35 -0000 1.9 +++ struts-faces.xml 8 Aug 2004 03:28:35 -0000 1.10 @@ -177,6 +177,16 @@ </attribute> <attribute> + <name>property</name> + <required>false</required> + <rtexprvalue>false</rtexprvalue> + <description> + Component of the component for which to render errors. If not + specified, only global messages are rendered. + </description> + </attribute> + + <attribute> <name>rendered</name> <required>false</required> <rtexprvalue>false</rtexprvalue> 1.4 +3 -0 jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/application/ViewHandlerImpl.java Index: ViewHandlerImpl.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/application/ViewHandlerImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ViewHandlerImpl.java 7 Jul 2004 22:08:56 -0000 1.3 +++ ViewHandlerImpl.java 8 Aug 2004 03:28:35 -0000 1.4 @@ -113,6 +113,9 @@ public void renderView(FacesContext context, UIViewRoot view) throws IOException, FacesException { + if (log.isDebugEnabled()) { + log.debug("renderView(" + view.getViewId() + ")"); + } ExternalContext econtext = context.getExternalContext(); if (econtext.getSession(false) != null) { Locale locale = (Locale) 1.2 +36 -1 jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/component/ErrorsComponent.java Index: ErrorsComponent.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/component/ErrorsComponent.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ErrorsComponent.java 8 Jul 2004 01:11:28 -0000 1.1 +++ ErrorsComponent.java 8 Aug 2004 03:28:35 -0000 1.2 @@ -56,6 +56,12 @@ private String bundle = null; + /** + * <p>Property name of the property to report errors for.</p> + */ + private String property = null; + + // ---------------------------------------------------- Component Properties @@ -96,6 +102,33 @@ } + /** + * <p>Return the property name for which to report errors.</p> + */ + public String getProperty() { + + ValueBinding vb = getValueBinding("property"); + if (vb != null) { + return (String) vb.getValue(getFacesContext()); + } else { + return property; + } + + } + + + /** + * <p>Set the property name for which to report errors.</p> + * + * @param property The new property name + */ + public void setProperty(String property) { + + this.property = property; + + } + + // ---------------------------------------------------- StateManager Methods @@ -110,6 +143,7 @@ Object values[] = (Object[]) state; super.restoreState(context, values[0]); bundle = (String) values[1]; + property = (String) values[2]; } @@ -121,9 +155,10 @@ */ public Object saveState(FacesContext context) { - Object values[] = new Object[2]; + Object values[] = new Object[3]; values[0] = super.saveState(context); values[1] = bundle; + values[2] = property; return values; } 1.9 +16 -3 jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/renderer/ErrorsRenderer.java Index: ErrorsRenderer.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/renderer/ErrorsRenderer.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ErrorsRenderer.java 26 Jul 2004 19:34:49 -0000 1.8 +++ ErrorsRenderer.java 8 Aug 2004 03:28:35 -0000 1.9 @@ -98,9 +98,18 @@ // Set up to render the error messages appropriately boolean headerDone = false; ResponseWriter writer = context.getResponseWriter(); + String id = component.getId(); + String property = (String) component.getAttributes().get("property"); + if (id != null) { + writer.startElement("span", component); + if (id != null) { + writer.writeAttribute("id", component.getClientId(context), + "id"); + } + } // Render any JavaServer Faces messages - Iterator messages = context.getMessages(); + Iterator messages = context.getMessages(property); while (messages.hasNext()) { FacesMessage message = (FacesMessage) messages.next(); if (!headerDone) { @@ -124,7 +133,8 @@ context.getExternalContext().getRequestMap().get (Globals.ERROR_KEY); if (errors != null) { - Iterator reports = errors.get(); + Iterator reports = errors.get + ((property == null) ? ActionErrors.GLOBAL_ERROR : property); while (reports.hasNext()) { ActionMessage report = (ActionMessage) reports.next(); if (!headerDone) { @@ -151,6 +161,9 @@ // Append the list footer if needed if (headerDone && footerPresent) { writer.write(resources.getMessage(locale, "errors.footer")); + } + if (id != null) { + writer.endElement("span"); } } 1.9 +39 -1 jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/taglib/ErrorsTag.java Index: ErrorsTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/java/org/apache/struts/faces/taglib/ErrorsTag.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ErrorsTag.java 8 Jul 2004 01:11:28 -0000 1.8 +++ ErrorsTag.java 8 Aug 2004 03:28:35 -0000 1.9 @@ -17,6 +17,7 @@ package org.apache.struts.faces.taglib; +import javax.faces.component.UIComponent; /** @@ -33,6 +34,16 @@ // ---------------------------------------------------------- Tag Attributes + /** + * <p>The property name for which to report errors.</p> + */ + protected String property = null; + + public void setProperty(String property) { + this.property = property; + } + + // ---------------------------------------------------------- Public Methods @@ -53,6 +64,33 @@ public String getRendererType() { return ("org.apache.struts.faces.Errors"); + + } + + + /** + * <p>Release any variables allocated during use of this tag instance.</p> + */ + public void release() { + + super.release(); + this.property = null; + + } + + + // -------------------------------------------------- UIComponentTag Methods + + + /** + * <p>Override attributes set on this tag instance.</p> + * + * @param component Component whose attributes should be overridden + */ + protected void setProperties(UIComponent component) { + + super.setProperties(component); + setStringAttribute(component, "property", property); } 1.2 +21 -1 jakarta-struts/contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient/AbstractTestCase.java Index: AbstractTestCase.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient/AbstractTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractTestCase.java 3 Aug 2004 07:01:08 -0000 1.1 +++ AbstractTestCase.java 8 Aug 2004 03:28:35 -0000 1.2 @@ -23,7 +23,9 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlHead; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; @@ -234,6 +236,24 @@ */ this.page = page; return (page); + + } + + + /** + * <p>Submit the current page, using the specified component, and retrieve + * the subsequent page, saving a reference so that other utility methods + * may be used to retrieve information from it.</p> + * + * @param submit Submit component to click + * + * @exception IOException if an input/output error occurs + */ + protected HtmlPage submit(HtmlSubmitInput submit) throws IOException { + + HtmlPage page = (HtmlPage) submit.click(); + this.page = page; + return page; } 1.3 +1 -4 jakarta-struts/contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient/SimpleTestCase.java Index: SimpleTestCase.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient/SimpleTestCase.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SimpleTestCase.java 7 Aug 2004 04:53:35 -0000 1.2 +++ SimpleTestCase.java 8 Aug 2004 03:28:35 -0000 1.3 @@ -36,9 +36,6 @@ import junit.framework.TestCase; import junit.framework.TestSuite; -import org.apache.commons.httpclient.Cookie; -import org.apache.commons.httpclient.HttpState; - /** * <p>Test case for a simple Struts-Faces page that is statically examined 1.1 jakarta-struts/contrib/struts-faces/src/sysclient/org/apache/struts/faces/sysclient/LogonTestCase.java Index: LogonTestCase.java =================================================================== /* * Copyright 2002,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.struts.faces.sysclient; import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlBase; import com.gargoylesoftware.htmlunit.html.HtmlBody; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlHead; import com.gargoylesoftware.htmlunit.html.HtmlLink; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; import com.gargoylesoftware.htmlunit.html.HtmlResetInput; import com.gargoylesoftware.htmlunit.html.HtmlSpan; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * <p>Test case for a logon form that accepts a username and password.</p> * * @version $Revision: 1.1 $ $Date: 2004/08/08 03:28:35 $ */ public class LogonTestCase extends AbstractTestCase { // ------------------------------------------------------------ Constructors /** * <p>Construct a new instance of this test case.</p> * * @param name Name of the new test case */ public LogonTestCase(String name) { super(name); } // ------------------------------------------------------ Instance Variables // ------------------------------------------------------ Test Setup Methods /** * <p>Set up the instance variables required for this test case.</p> */ public void setUp() throws Exception { super.setUp(); page("/logon.faces"); } /** * <p>Return the set of tests included in this test suite.</p> */ public static Test suite() { return (new TestSuite(LogonTestCase.class)); } /** * <p>Tear down instance variables required by this test case.</p> */ public void tearDown() { super.tearDown(); } // ------------------------------------------------- Individual Test Methods /** * <p>Submit incorrect input fields and verify the correct response.</p> */ public void testIncorrect() throws Exception { HtmlSpan span = null; HtmlTextInput username = (HtmlTextInput) element("form:username"); HtmlPasswordInput password = (HtmlPasswordInput) element("form:password"); HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit"); username.setValueAttribute("bb"); password.setValueAttribute(""); submit(submit); assertEquals("logon", title()); span = (HtmlSpan) element("globalErrors"); assertNotNull(span); assertEquals("", span.asText()); username = (HtmlTextInput) element("form:username"); assertNotNull(username); assertEquals("bb", username.getValueAttribute()); span = (HtmlSpan) element("form:usernameErrors"); assertNotNull(span); // FIXME: response string should really include "Username:" assertEquals("[EH][EP] can not be less than 3 characters.[ES][EF]", span.asText()); password = (HtmlPasswordInput) element("form:password"); assertNotNull(password); assertEquals("", password.getValueAttribute()); span = (HtmlSpan) element("form:passwordErrors"); assertNotNull(span); // FIXME: response string should really include "Password:" assertEquals("[EH][EP] is required.[ES][EF]", span.asText()); } /** * <p>Verify the content of a pristine page returned when executing this * view for the first time.</p> */ public void testPristine() throws Exception { HtmlSpan span = null; HtmlElement html = (HtmlElement) page; assertEquals("html", html.getTagName()); assertEquals("http://www.w3.org/1999/xhtml", html.getAttributeValue("xmlns")); assertEquals("logon", title()); HtmlForm form = (HtmlForm) element("form"); assertNotNull(form); assertEquals("", form.getAcceptAttribute()); assertEquals("", form.getAcceptCharsetAttribute()); String url = this.url.toString(); url = url.substring(0, url.length() - 1); url = url.substring(url.lastIndexOf('/')); String action = form.getActionAttribute(); int semicolon = action.indexOf(';'); if (semicolon >= 0) { action = action.substring(0, semicolon); } assertEquals(url + "/logon.faces", action); assertEquals("", form.getEnctypeAttribute()); assertEquals("post", form.getMethodAttribute()); assertEquals("", form.getNameAttribute()); assertEquals("", form.getOnResetAttribute()); assertEquals("", form.getOnSubmitAttribute()); assertEquals("", form.getTargetAttribute()); span = (HtmlSpan) element("form:usernamePrompt"); assertNotNull(span); assertEquals("Username:", span.asText()); HtmlTextInput username = (HtmlTextInput) element("form:username"); assertNotNull(username); assertEquals("", username.getLangAttribute()); assertEquals("form:username", username.getNameAttribute()); assertEquals("", username.getOnClickAttribute()); assertEquals("", username.getOnDblClickAttribute()); assertEquals("", username.getOnKeyDownAttribute()); assertEquals("", username.getOnKeyPressAttribute()); assertEquals("", username.getOnKeyUpAttribute()); assertEquals("", username.getOnMouseDownAttribute()); assertEquals("", username.getOnMouseMoveAttribute()); assertEquals("", username.getOnMouseOutAttribute()); assertEquals("", username.getOnMouseOverAttribute()); assertEquals("", username.getOnMouseUpAttribute()); assertEquals("text", username.getTypeAttribute()); assertEquals("", username.getValueAttribute()); span = (HtmlSpan) element("form:passwordPrompt"); assertNotNull(span); assertEquals("Password:", span.asText()); HtmlPasswordInput password = (HtmlPasswordInput) element("form:password"); assertNotNull(password); assertEquals("", password.getLangAttribute()); assertEquals("form:password", password.getNameAttribute()); assertEquals("", password.getOnClickAttribute()); assertEquals("", password.getOnDblClickAttribute()); assertEquals("", password.getOnKeyDownAttribute()); assertEquals("", password.getOnKeyPressAttribute()); assertEquals("", password.getOnKeyUpAttribute()); assertEquals("", password.getOnMouseDownAttribute()); assertEquals("", password.getOnMouseMoveAttribute()); assertEquals("", password.getOnMouseOutAttribute()); assertEquals("", password.getOnMouseOverAttribute()); assertEquals("", password.getOnMouseUpAttribute()); assertEquals("password", password.getTypeAttribute()); assertEquals("", password.getValueAttribute()); HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit"); assertNotNull(submit); assertEquals("", submit.getLangAttribute()); assertEquals("form:submit", submit.getNameAttribute()); assertEquals("", submit.getOnClickAttribute()); assertEquals("", submit.getOnDblClickAttribute()); assertEquals("", submit.getOnKeyDownAttribute()); assertEquals("", submit.getOnKeyPressAttribute()); assertEquals("", submit.getOnKeyUpAttribute()); assertEquals("", submit.getOnMouseDownAttribute()); assertEquals("", submit.getOnMouseMoveAttribute()); assertEquals("", submit.getOnMouseOutAttribute()); assertEquals("", submit.getOnMouseOverAttribute()); assertEquals("", submit.getOnMouseUpAttribute()); assertEquals("submit", submit.getTypeAttribute()); assertEquals("Logon", submit.getValueAttribute()); HtmlResetInput reset = (HtmlResetInput) element("form:reset"); assertNotNull(reset); assertEquals("", reset.getLangAttribute()); assertEquals("form:reset", reset.getNameAttribute()); assertEquals("", reset.getOnClickAttribute()); assertEquals("", reset.getOnDblClickAttribute()); assertEquals("", reset.getOnKeyDownAttribute()); assertEquals("", reset.getOnKeyPressAttribute()); assertEquals("", reset.getOnKeyUpAttribute()); assertEquals("", reset.getOnMouseDownAttribute()); assertEquals("", reset.getOnMouseMoveAttribute()); assertEquals("", reset.getOnMouseOutAttribute()); assertEquals("", reset.getOnMouseOverAttribute()); assertEquals("", reset.getOnMouseUpAttribute()); assertEquals("reset", reset.getTypeAttribute()); assertEquals("Reset", reset.getValueAttribute()); HtmlSubmitInput cancel = (HtmlSubmitInput) element("form:cancel"); assertNotNull(cancel); assertEquals("", cancel.getLangAttribute()); assertEquals("form:cancel", cancel.getNameAttribute()); assertEquals("", cancel.getOnClickAttribute()); assertEquals("", cancel.getOnDblClickAttribute()); assertEquals("", cancel.getOnKeyDownAttribute()); assertEquals("", cancel.getOnKeyPressAttribute()); assertEquals("", cancel.getOnKeyUpAttribute()); assertEquals("", cancel.getOnMouseDownAttribute()); assertEquals("", cancel.getOnMouseMoveAttribute()); assertEquals("", cancel.getOnMouseOutAttribute()); assertEquals("", cancel.getOnMouseOverAttribute()); assertEquals("", cancel.getOnMouseUpAttribute()); assertEquals("submit", cancel.getTypeAttribute()); assertEquals("Cancel", cancel.getValueAttribute()); } /** * <p>Submit known-bad mismatch and verify the correct response.</p> */ public void testMismatch() throws Exception { HtmlSpan span = null; HtmlTextInput username = (HtmlTextInput) element("form:username"); HtmlPasswordInput password = (HtmlPasswordInput) element("form:password"); HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit"); username.setValueAttribute("baduser"); password.setValueAttribute("badpass"); submit(submit); assertEquals("logon", title()); span = (HtmlSpan) element("globalErrors"); assertNotNull(span); assertEquals("[EH][EP]Invalid username/password combination[ES][EF]", span.asText()); username = (HtmlTextInput) element("form:username"); assertNotNull(username); assertEquals("baduser", username.getValueAttribute()); span = (HtmlSpan) element("form:usernameErrors"); assertNotNull(span); assertEquals("", span.asText()); password = (HtmlPasswordInput) element("form:password"); assertNotNull(password); assertEquals("", password.getValueAttribute()); span = (HtmlSpan) element("form:passwordErrors"); assertNotNull(span); assertEquals("", span.asText()); } /** * <p>Submit known-good username and password values, and * verify the correct response.</p> */ public void testSuccessful() throws Exception { HtmlTextInput username = (HtmlTextInput) element("form:username"); HtmlPasswordInput password = (HtmlPasswordInput) element("form:password"); HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit"); username.setValueAttribute("gooduser"); password.setValueAttribute("goodpass"); submit(submit); assertEquals("logon1", title()); } } 1.2 +22 -0 jakarta-struts/contrib/struts-faces/src/systest/org/apache/struts/faces/systest/ApplicationResources.properties Index: ApplicationResources.properties =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/src/systest/org/apache/struts/faces/systest/ApplicationResources.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ApplicationResources.properties 7 Aug 2004 04:53:35 -0000 1.1 +++ ApplicationResources.properties 8 Aug 2004 03:28:35 -0000 1.2 @@ -1,7 +1,29 @@ +button.cancel=Cancel +button.logon=Logon +button.reset=Reset errors.header=[EH] errors.footer=[EF] errors.prefix=[EP] errors.suffix=[ES] +errors.required={0} is required. +errors.minlength={0} can not be less than {1} characters. +errors.maxlength={0} can not be more than {1} characters. +errors.invalid={0} is invalid. +errors.byte={0} must be a byte. +errors.short={0} must be a short. +errors.integer={0} must be an integer. +errors.long={0} must be a long. +errors.float={0} must be a float. +errors.double={0} must be a double. +errors.date={0} is not a date. +errors.range={0} is not in the range {1} through {2}. +errors.creditcard={0} is an invalid credit card number. +errors.email={0} is an invalid e-mail address. +logon.username=Username is required +logon.password=Password is required +logon.mismatch=Invalid username/password combination +prompt.username=Username: +prompt.password=Password: resource.simple=Resource Simple Text resource.filtered=Resource <b>Filtered</b> Text resource.unfiltered=Resource <b>Unfiltered</b> Text 1.1 jakarta-struts/contrib/struts-faces/src/systest/org/apache/struts/faces/systest/LogonAction.java Index: LogonAction.java =================================================================== /* * Copyright 2002,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.struts.faces.systest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; /** * <p>Action to process logon attempts. It accepts only the combination * "gooduser" and "goodpass", while rejecting all others. Successful * login requests a logical forward "login1", while unsuccessful login * returns to the input form.</p> */ public class LogonAction extends Action { private static final Log log = LogFactory.getLog(LogonAction.class); /** * <p>Process an attempted logon.</p> */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionErrors errors = new ActionErrors(); String username = (String) PropertyUtils.getSimpleProperty(form, "username"); if ((username == null) || ("".equals(username))) { errors.add("username", new ActionError("logon.username")); } String password = (String) PropertyUtils.getSimpleProperty(form, "password"); if ((password == null) || ("".equals(password))) { errors.add("password", new ActionError("logon.password")); } if (log.isTraceEnabled()) { log.trace("username=" + username + ",password=" + password); } if (errors.isEmpty() && (!"gooduser".equals(username) || !"goodpass".equals(password))) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("logon.mismatch")); } if (errors.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Successful logon, forwarding to logon1"); } return (mapping.findForward("logon1")); } else { if (log.isDebugEnabled()) { log.debug("Unsuccessful logon, returning to input"); } saveErrors(request, errors); return (mapping.getInputForward()); } } } 1.1 jakarta-struts/contrib/struts-faces/web/systest/logon.jsp Index: logon.jsp =================================================================== <!-- Copyright 2002,2004 The Apache Software Foundation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <%@ page contentType="text/html;charset=UTF-8" %> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %> <%@ taglib prefix="s" uri="http://jakarta.apache.org/struts/tags-faces" %> <f:view> <s:html locale="true" xhtml="true"> <head> <title>logon</title> </head> <body> <s:loadMessages messages="messages" var="messages"/> <s:errors id="globalErrors" bundle="messages"/> <s:form id="form" action="/logon"> <h:panelGrid columns="3"> <h:outputText id="usernamePrompt" value="#{messages['prompt.username']}"/> <h:inputText id="username" value="#{logonForm.username}"/> <s:errors id="usernameErrors" bundle="messages" property="username"/> <h:outputText id="passwordPrompt" value="#{messages['prompt.password']}"/> <h:inputSecret id="password" value="#{logonForm.password}"/> <s:errors id="passwordErrors" bundle="messages" property="password"/> <h:commandButton id="submit" type="SUBMIT" value="#{messages['button.logon']}"/> <h:commandButton id="reset" type="RESET" value="#{messages['button.reset']}"/> <h:commandButton id="cancel" type="SUBMIT" value="#{messages['button.cancel']}"/> </h:panelGrid> </s:form> </body> </s:html> </f:view> 1.1 jakarta-struts/contrib/struts-faces/web/systest/logon1.jsp Index: logon1.jsp =================================================================== <!-- Copyright 2002,2004 The Apache Software Foundation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <%@ page contentType="text/html;charset=UTF-8" %> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %> <%@ taglib prefix="s" uri="http://jakarta.apache.org/struts/tags-faces" %> <f:view> <s:html locale="true" xhtml="true"> <head> <title>logon1</title> <s:base/> <s:stylesheet path="/stylesheet.css"/> </head> <body> </body> </s:html> </f:view> 1.3 +19 -106 jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/struts-config.xml Index: struts-config.xml =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/struts-config.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- struts-config.xml 7 Aug 2004 04:53:35 -0000 1.2 +++ struts-config.xml 8 Aug 2004 03:28:35 -0000 1.3 @@ -24,14 +24,8 @@ <!-- - This is the Struts configuration file for the example application, - using the proposed new syntax. - - NOTE: You would only flesh out the details in the "form-bean" - declarations if you had a generator tool that used them to create - the corresponding Java classes for you. Otherwise, you would - need only the "form-bean" element itself, with the corresponding - "name" and "type" attributes. + This is the Struts configuration file for the Struts-Faces system + integration test webapp. --> @@ -42,117 +36,38 @@ <!-- ========== Form Bean Definitions =================================== --> <form-beans> - <!-- Logon form bean --> -<!-- - <form-bean name="logonForm" - type="org.apache.struts.validator.DynaValidatorForm"> + <!-- Logon Form Bean --> + <form-bean name="logonForm" + type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="username" type="java.lang.String"/> <form-property name="password" type="java.lang.String"/> </form-bean> ---> - - <!-- Registration form bean --> -<!-- - <form-bean name="registrationForm" - type="org.apache.struts.webapp.example.RegistrationForm"/> ---> - - <!-- Subscription form bean --> -<!-- - <form-bean name="subscriptionForm" - type="org.apache.struts.webapp.example.SubscriptionForm"/> ---> </form-beans> <!-- ========== Global Forward Definitions ============================== --> <global-forwards> -<!-- - <forward name="logoff" path="/logoff.do"/> - <forward name="logon" path="/logon.faces"/> - <forward name="registration" path="/registration.faces"/> - <forward name="subscription" path="/subscription.faces"/> - <forward name="success" path="/mainMenu.faces"/> ---> - </global-forwards> - - <!-- ========== Action Mapping Definitions ============================== --> - <action-mappings> + <forward name="logon" + path="/logon.jsp"/> - <!-- Edit user registration --> -<!-- - <action path="/editRegistration" - type="org.apache.struts.webapp.example.EditRegistrationAction" - attribute="registrationForm" - scope="request" - validate="false"> - <forward name="success" path="/registration.faces"/> - </action> ---> + <forward name="logon1" + path="/logon1.jsp"/> - <!-- Edit mail subscription --> -<!-- - <action path="/editSubscription" - type="org.apache.struts.webapp.example.EditSubscriptionAction" - attribute="subscriptionForm" - scope="request" - validate="false"> - <forward name="failure" path="/mainMenu.faces"/> - <forward name="success" path="/subscription.faces"/> - </action> ---> - - <!-- Process a user logoff --> -<!-- - <action path="/logoff" - type="org.apache.struts.webapp.example.LogoffAction"> - <forward name="success" path="/index.faces"/> - </action> ---> - - <!-- Process a user logon --> -<!-- - <action path="/logon" - type="org.apache.struts.webapp.example.LogonAction" - name="logonForm" - scope="request" - input="logon"> - <exception - key="expired.password" - type="org.apache.struts.webapp.example.ExpiredPasswordException" - path="/changePassword.faces"/> - </action> ---> - - <!-- Save user registration --> -<!-- - <action path="/saveRegistration" - type="org.apache.struts.webapp.example.SaveRegistrationAction" - name="registrationForm" - scope="request" - input="registration"/> ---> + </global-forwards> - <!-- Save mail subscription --> -<!-- - <action path="/saveSubscription" - type="org.apache.struts.webapp.example.SaveSubscriptionAction" - name="subscriptionForm" - scope="request" - input="subscription"> - <forward name="success" path="/editRegistration.do?action=Edit"/> - </action> ---> + <!-- ========== Action Mapping Definitions ============================== --> + <action-mappings> - <!-- Display the "walking tour" documentation --> -<!-- - <action path="/tour" - forward="/tour.htm"> - </action> ---> + <!-- Execute Logon Action --> + <action path="/logon" + type="org.apache.struts.faces.systest.LogonAction" + input="logon" + name="logonForm" + scope="request" + validate="true"/> </action-mappings> @@ -177,12 +92,10 @@ <!-- ========== Plug Ins Configuration ================================== --> -<!-- <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/> </plug-in> ---> </struts-config> 1.1 jakarta-struts/contrib/struts-faces/web/systest/WEB-INF/validation.xml Index: validation.xml =================================================================== <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd"> <!-- Copyright 2002,2004 The Apache Software Foundation. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Validation Rules for the Struts-Faces System Integration Test Webapp $Id: validation.xml,v 1.1 2004/08/08 03:28:35 craigmcc Exp $ --> <form-validation> <formset> <form name="logonForm"> <field property="username" depends="required,minlength,maxlength"> <!-- <arg position="0" bundle="messages" key="prompt.username"/> <arg position="1" name="minlength" resource="false" key="${var:minlength}"/> <arg position="2" name="maxlength" resource="false" key="${var:maxlength}"/> --> <arg0 key="prompt.username"/> <arg1 key="${var:minlength}" name="minlength" resource="false"/> <arg2 key="${var:maxlength}" name="maxlength" resource="false"/> <var> <var-name>maxlength</var-name> <var-value>16</var-value> </var> <var> <var-name>minlength</var-name> <var-value>3</var-value> </var> </field> <field property="password" depends="required,minlength,maxlength"> <arg0 key="prompt.password"/> <arg1 key="${var:minlength}" name="minlength" resource="false"/> <arg2 key="${var:maxlength}" name="maxlength" resource="false"/> <var> <var-name>maxlength</var-name> <var-value>16</var-value> </var> <var> <var-name>minlength</var-name> <var-value>3</var-value> </var> </field> </form> </formset> </form-validation>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]