You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2005/12/07 05:45:24 UTC

svn commit: r354709 - in /beehive/trunk/samples/netui-samples: src/org/apache/beehive/samples/netui/customValidator/ src/org/apache/beehive/samples/netui/resources/clientsidevalidation/ src/org/apache/beehive/samples/netui/resources/customvalidator/ we...

Author: rich
Date: Tue Dec  6 20:45:15 2005
New Revision: 354709

URL: http://svn.apache.org/viewcvs?rev=354709&view=rev
Log:
Added a sample on enabling Struts client-side validation in NetUI.


Added:
    beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/clientsidevalidation/
    beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/clientsidevalidation/messages.properties   (with props)
    beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/customvalidator/
    beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/customvalidator/messages.properties
      - copied unchanged from r354114, beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/customValidator/Messages.properties
    beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/
    beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/Controller.java   (with props)
    beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/index.jsp   (with props)
    beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/success.jsp   (with props)
Removed:
    beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/customValidator/Messages.properties
Modified:
    beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/customValidator/MyFormBean.java
    beehive/trunk/samples/netui-samples/web/index.jsp

Modified: beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/customValidator/MyFormBean.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/customValidator/MyFormBean.java?rev=354709&r1=354708&r2=354709&view=diff
==============================================================================
--- beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/customValidator/MyFormBean.java (original)
+++ beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/customValidator/MyFormBean.java Tue Dec  6 20:45:15 2005
@@ -6,7 +6,7 @@
  * This is the form bean for the "Custom Validator" sample.  It defines its own message bundle, but
  * you could also just use messages in the page flow's default message bundle.
  */
-@Jpf.FormBean(messageBundle="org.apache.beehive.samples.netui.customValidator.Messages")
+@Jpf.FormBean(messageBundle="org.apache.beehive.samples.netui.resources.customvalidator.messages")
 public class MyFormBean
 {
     private String _palindrome;

Added: beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/clientsidevalidation/messages.properties
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/clientsidevalidation/messages.properties?rev=354709&view=auto
==============================================================================
--- beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/clientsidevalidation/messages.properties (added)
+++ beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/clientsidevalidation/messages.properties Tue Dec  6 20:45:15 2005
@@ -0,0 +1,8 @@
+displayname.fullName=your full name
+displayname.email=the email address
+
+errors.required=Please fill in a value for {0}.
+errors.minlength=The value for {0} must be at least {1} characters.
+errors.letters=The value for {0} may only contain letters and spaces.
+errors.email=Please use a valid email address for {0}.
+

Propchange: beehive/trunk/samples/netui-samples/src/org/apache/beehive/samples/netui/resources/clientsidevalidation/messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/Controller.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/Controller.java?rev=354709&view=auto
==============================================================================
--- beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/Controller.java (added)
+++ beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/Controller.java Tue Dec  6 20:45:15 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package advanced.clientSideValidation;
+
+import org.apache.beehive.netui.pageflow.PageFlowController;
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+
+/**
+ * This is the page flow controller for the Client-side Validation sample.
+ */
+@Jpf.Controller(
+    simpleActions={
+        @Jpf.SimpleAction(name="begin", path="index.jsp")
+    },
+    messageBundles={
+        @Jpf.MessageBundle(bundlePath="org.apache.beehive.samples.netui.resources.clientsidevalidation.messages")
+    }
+)
+public class Controller extends PageFlowController
+{
+    @Jpf.Action(
+        forwards={
+            @Jpf.Forward(name="success", path="success.jsp")
+        },
+        validationErrorForward=@Jpf.Forward(name="failure", path="index.jsp")
+    )
+    public Forward submit(MyForm form)
+    {
+        return new Forward("success");
+    }
+
+    /**
+     * The form bean, with validation annotations on its properties.
+     */
+    public static class MyForm implements java.io.Serializable
+    {
+        private String _fullName;
+        private String _email;
+
+        @Jpf.ValidatableProperty(
+            displayNameKey="displayname.fullName",
+            validateRequired=@Jpf.ValidateRequired(messageKey="errors.required"),
+            validateMinLength=@Jpf.ValidateMinLength(chars=3, messageKey="errors.minlength"),
+            validateMask=@Jpf.ValidateMask(regex="^[A-Za-z ]*$", messageKey="errors.letters")
+        )
+        public String getFullName()
+        {
+            return _fullName;
+        }
+
+        public void setFullName(String fullName)
+        {
+            _fullName = fullName;
+        }
+     
+        @Jpf.ValidatableProperty(
+            displayNameKey="displayname.email",
+            validateRequired=@Jpf.ValidateRequired(messageKey="errors.required"),
+            validateEmail=@Jpf.ValidateEmail(messageKey="errors.email")
+        )
+        public String getEmail()
+        {
+            return _email;
+        }
+
+        public void setEmail(String email)
+        {
+            _email = email;
+        }
+    }
+}

Propchange: beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/Controller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/index.jsp
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/index.jsp?rev=354709&view=auto
==============================================================================
--- beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/index.jsp (added)
+++ beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/index.jsp Tue Dec  6 20:45:15 2005
@@ -0,0 +1,84 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%>
+<%@ taglib prefix="netui-data" uri="http://beehive.apache.org/netui/tags-databinding-1.0"%>
+<%@ taglib prefix="netui-template" uri="http://beehive.apache.org/netui/tags-template-1.0"%>
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
+
+<netui-template:template templatePage="/resources/template/template.jsp">
+    <netui-template:setAttribute name="sampleTitle" value="Client-side Validation"/>
+    <netui-template:section name="main">
+        <p>
+            This sample demonstrates enabling client-side validation for declarative validation
+            annotations.  NetUI does not provide its own client-side validation framework, but
+            the Struts JavaScriptValidatorTag can be used to enable client-side validation.
+        </p>
+        <p>
+            In general, to use client-side validation with NetUI, you must do the following...
+        </p>
+        <p>
+            <b>...in your page flow controller class:</b>
+        </p>
+            <ul>
+                <li>
+                    Add a
+                    <code><a href="http://beehive.apache.org/docs/1.0/apidocs/classref_netui/org/apache/beehive/netui/pageflow/annotations/Jpf.MessageBundle.html">@Jpf.MessageBundle</a></code>
+                    annotation to the page flow controller, even if your validation annotations
+                    use hardcoded messages (without message keys).
+                </li>
+                <li>
+                    Provide a message for each validation annotation, using either its
+                    <code><a href="http://beehive.apache.org/docs/1.0/apidocs/classref_netui/org/apache/beehive/netui/pageflow/annotations/Jpf.ValidateRequired.html#messageKey()">messageKey</a></code>
+                    or its
+                    <code><a href="http://beehive.apache.org/docs/1.0/apidocs/classref_netui/org/apache/beehive/netui/pageflow/annotations/Jpf.ValidateRequired.html#message()">message</a></code>
+                    attribute.
+                </li>
+            </ul>
+        </p>
+        <p>
+            <b>...in your JSP:</b>
+        </p>
+        <ul>
+            <li>
+                Import the Struts HTML tag library: <code>&lt;%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %&gt;</code>.
+            </li>
+            <li>
+                Add the Struts <code>&lt;html:javascript&gt;</code> somewhere after the form on the page.
+            <li>
+                Give your <code>&lt;netui:form&gt;</code> a <code>tagId</code>, and use this ID
+                as the <code>formName</code> in your <code>&lt;html:javascript&gt;</code> tag.
+            </li>
+            <li>
+                Choose a unique validation method name for the <code>method</code> attribute on
+                <code>&lt;html:javascript&gt;</code>, and add a call to this method in your
+                <code>&lt;netui:form&gt;</code>'s <code>onSubmit</code>, like this:
+                <code>onSubmit="return myValidationMethod(this)"</code>.
+            </li>
+            <li>
+                Give each form input a <code>tagId</code>, which must be the
+                <strong>property name</strong> of the input field.  For example, if a text box
+                has a datasource of <code>actionForm.myProperty</code>, you would use
+                <code>myProperty</code> as the <code>tagId</code>.
+            </li>
+        </ul>
+
+        <br/>
+        <hr/>
+        <netui:form action="submit" tagId="myForm" onSubmit="return doValidation(this)">
+            <table>
+                <tr>
+                    <td>Full Name (required, 3 or more characters, letters and spaces, e.g., "Jane Doe"):</td>
+                    <td><netui:textBox dataSource="actionForm.fullName" tagId="fullName"/></td>
+                    <td><span<netui:error key="fullName"/></td>
+                <tr>
+                    <td>Email Address (required, must be a valid email address, e.g., "jane@doe.com"):</td>
+                    <td><netui:textBox dataSource="actionForm.email" tagId="email"/></td>
+                    <td><span<netui:error key="email"/></td>
+                </tr>
+            </table>
+            <br/>
+            <netui:button value="submit"/>
+        </netui:form>
+
+        <html:javascript formName="myForm" method="doValidation"/>
+    </netui-template:section>
+</netui-template:template>

Propchange: beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/index.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/success.jsp
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/success.jsp?rev=354709&view=auto
==============================================================================
--- beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/success.jsp (added)
+++ beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/success.jsp Tue Dec  6 20:45:15 2005
@@ -0,0 +1,15 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%>
+<%@ taglib prefix="netui-data" uri="http://beehive.apache.org/netui/tags-databinding-1.0"%>
+<%@ taglib prefix="netui-template" uri="http://beehive.apache.org/netui/tags-template-1.0"%>
+
+
+<netui-template:template templatePage="/resources/template/template.jsp">
+    <netui-template:setAttribute name="sampleTitle" value="Client-side Validation"/>
+    <netui-template:section name="main">
+        Valiation passed.
+        <br/>
+        <br/>
+        <netui:anchor action="begin">start over</netui:anchor>
+    </netui-template:section>
+</netui-template:template>

Propchange: beehive/trunk/samples/netui-samples/web/advanced/clientSideValidation/success.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: beehive/trunk/samples/netui-samples/web/index.jsp
URL: http://svn.apache.org/viewcvs/beehive/trunk/samples/netui-samples/web/index.jsp?rev=354709&r1=354708&r2=354709&view=diff
==============================================================================
--- beehive/trunk/samples/netui-samples/web/index.jsp (original)
+++ beehive/trunk/samples/netui-samples/web/index.jsp Tue Dec  6 20:45:15 2005
@@ -123,6 +123,10 @@
               after all actions (or specific actions), and can change an action's destination.</dd>
       </dl>
       <dl>
+          <dt><netui:anchor href="advanced/clientSideValidation/Controller.jpf" value="Client-side Validation"/></dt>
+          <dd>Demonstrates the enabling of Struts client-side validation in NetUI.</dd>
+      </dl>
+      <dl>
           <dt><netui:anchor href="advanced/customValidator/Controller.jpf" value="Custom Validator"/></dt>
           <dd>Demonstrates the use of custom Commons Validator rules through annotations.</dd>
       </dl>