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

svn commit: r178255 - in /incubator/beehive/trunk/samples/netui-samples: ./ WEB-INF/src/org/apache/beehive/samples/netui/resources/formposting/ ui/formposting/

Author: ekoneil
Date: Tue May 24 12:31:21 2005
New Revision: 178255

URL: http://svn.apache.org/viewcvs?rev=178255&view=rev
Log:
Add a formposting example including:

- basic form posting
- form posting with an output form
- form posting with validation

BB: self
DRT: netui-samples builds / runs


Added:
    incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/formposting/
    incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/formposting/messages.properties
    incubator/beehive/trunk/samples/netui-samples/ui/formposting/
    incubator/beehive/trunk/samples/netui-samples/ui/formposting/Controller.java
    incubator/beehive/trunk/samples/netui-samples/ui/formposting/basicForm.jsp
    incubator/beehive/trunk/samples/netui-samples/ui/formposting/index.jsp
    incubator/beehive/trunk/samples/netui-samples/ui/formposting/outputForm.jsp
    incubator/beehive/trunk/samples/netui-samples/ui/formposting/validatedForm.jsp
Modified:
    incubator/beehive/trunk/samples/netui-samples/index.jsp

Added: incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/formposting/messages.properties
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/formposting/messages.properties?rev=178255&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/formposting/messages.properties (added)
+++ incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/formposting/messages.properties Tue May 24 12:31:21 2005
@@ -0,0 +1,3 @@
+# Messages for ui/formposting/Controller.java
+
+formposting.invalidname=Please enter a valid name (hint, try "Frank")
\ No newline at end of file

Modified: incubator/beehive/trunk/samples/netui-samples/index.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/index.jsp?rev=178255&r1=178254&r2=178255&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/index.jsp (original)
+++ incubator/beehive/trunk/samples/netui-samples/index.jsp Tue May 24 12:31:21 2005
@@ -49,5 +49,9 @@
       <dt><netui:anchor href="validation/Controller.jpf" value="Validation"/></dt>
       <dd>This sample demonstrates the declarative validation model.</dd>
     </dl>
+    <dl>
+      <dt><netui:anchor href="ui/formposting/Controller.jpf" value="Form Posting"/></dt>
+      <dd>Demonstrates how to use a Page Flow and NetUI JSP tags to handle an HTML form POST.</dd>
+    </dl>
   </netui-template:section>
 </netui-template:template>

Added: incubator/beehive/trunk/samples/netui-samples/ui/formposting/Controller.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/ui/formposting/Controller.java?rev=178255&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/ui/formposting/Controller.java (added)
+++ incubator/beehive/trunk/samples/netui-samples/ui/formposting/Controller.java Tue May 24 12:31:21 2005
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2004-2005 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 ui.formposting;
+
+import java.io.Serializable;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.beehive.netui.pageflow.PageFlowController;
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.FormData;
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+
+@Jpf.Controller(
+    forwards={
+        @Jpf.Forward(name="basicFormSuccess", path="basicForm.jsp"),
+        @Jpf.Forward(name="outputFormSuccess", path="outputForm.jsp"),
+        @Jpf.Forward(name="validatedFormSuccess", path="validatedForm.jsp")
+    },
+    simpleActions={
+        @Jpf.SimpleAction(name="begin", path="index.jsp")
+    },
+    messageBundles={
+        @Jpf.MessageBundle(bundlePath="org.apache.beehive.samples.netui.resources.formposting.messages")
+    }
+)
+public class Controller
+    extends PageFlowController {
+
+    @Jpf.Action()
+    public Forward showBasicForm() {
+        return new Forward("basicFormSuccess");
+    }
+
+    @Jpf.Action()
+    public Forward postBasicForm(NameForm form) {
+        return new Forward("basicFormSuccess");
+    }
+
+    @Jpf.Action()
+    public Forward showOutputForm() {
+        NameForm outputForm = new NameForm();
+        outputForm.setName("Frank");
+        return new Forward("outputFormSuccess", outputForm);
+    }
+
+    @Jpf.Action()
+    public Forward postOutputForm(NameForm form) {
+        return new Forward("outputFormSuccess", form);
+    }
+
+    @Jpf.Action()
+    public Forward showValidatedForm() {
+        return new Forward("validatedFormSuccess");
+    }
+
+    @Jpf.Action(
+        validationErrorForward=@Jpf.Forward(name="failure", navigateTo=Jpf.NavigateTo.currentPage)
+    )
+    public Forward postValidatedForm(ValidatedNameForm form) {
+        return new Forward("validatedFormSuccess");
+    }
+
+    public static class NameForm
+        extends FormData
+        implements Serializable {
+
+        private String _name = null;
+
+        public String getName() {
+            return _name;
+        }
+
+        public void setName(String name) {
+            _name = name;
+        }
+    }
+
+    public static class ValidatedNameForm
+        extends NameForm {
+
+        private static final String REQUIRED_NAME = "Frank";
+
+        public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest servletRequest) {
+            ActionErrors errors = null;
+            if(!REQUIRED_NAME.equals(getName())) {
+                errors = new ActionErrors();
+                errors.add("name", new ActionMessage("formposting.invalidname"));
+            }
+
+            return errors;
+        }
+    }
+}

Added: incubator/beehive/trunk/samples/netui-samples/ui/formposting/basicForm.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/ui/formposting/basicForm.jsp?rev=178255&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/ui/formposting/basicForm.jsp (added)
+++ incubator/beehive/trunk/samples/netui-samples/ui/formposting/basicForm.jsp Tue May 24 12:31:21 2005
@@ -0,0 +1,35 @@
+<%--
+   Copyright 2004-2005 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:$
+--%>
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
+
+<netui-template:template templatePage="/resources/template/template.jsp">
+  <netui-template:setAttribute name="samTitle" value="Basic Form"/>
+  <netui-template:section name="main">
+      <i>Enter a name in this text box and click the Submit button to POST the value to the server.
+      <br/>Once the form has been submitted, the name will re-appear in this text box.</i><br/>
+      <br/>
+      <netui:form action="postBasicForm">
+          <netui:label value="Name:"/>&nbsp;<netui:textBox dataSource="actionForm.name"/><br/>
+          <br/>
+          <netui:button value="Submit"/>
+      </netui:form>
+  </netui-template:section>
+</netui-template:template>

Added: incubator/beehive/trunk/samples/netui-samples/ui/formposting/index.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/ui/formposting/index.jsp?rev=178255&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/ui/formposting/index.jsp (added)
+++ incubator/beehive/trunk/samples/netui-samples/ui/formposting/index.jsp Tue May 24 12:31:21 2005
@@ -0,0 +1,39 @@
+<%--
+   Copyright 2004-2005 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:$
+--%>
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
+
+<netui-template:template templatePage="/resources/template/template.jsp">
+  <netui-template:setAttribute name="samTitle" value="Form Posting"/>
+  <netui-template:section name="main">
+    <dl>
+      <dt><netui:anchor action="showBasicForm" value="Simple Post"/></dt>
+      <dd>Demonstrates a basic HTML form POST</dd>
+    </dl>
+    <dl>
+      <dt><netui:anchor action="showOutputForm" value="Simple Post with Output Form"/></dt>
+      <dd>Demonstrates the use of an output form used with an HTML form POST</dd>
+    </dl>
+      <dl>
+      <dt><netui:anchor action="showValidatedForm" value="Simple Post with Validation"/></dt>
+      <dd>Demonstrates the use of validation with an HTML form POST</dd>
+    </dl>
+  </netui-template:section>
+</netui-template:template>
\ No newline at end of file

Added: incubator/beehive/trunk/samples/netui-samples/ui/formposting/outputForm.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/ui/formposting/outputForm.jsp?rev=178255&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/ui/formposting/outputForm.jsp (added)
+++ incubator/beehive/trunk/samples/netui-samples/ui/formposting/outputForm.jsp Tue May 24 12:31:21 2005
@@ -0,0 +1,38 @@
+<%--
+   Copyright 2004-2005 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:$
+--%>
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
+
+<netui-template:template templatePage="/resources/template/template.jsp">
+  <netui-template:setAttribute name="samTitle" value="Basic Form"/>
+  <netui-template:section name="main">
+      <i>This NetUI form has been pre-populated with a value from an "output form" from
+         the Page Flow action postOutputForm.  <br/>Click the Submit button to POST the form
+         or change then name and then click Submit.  <br/>Once the form has been submitted,
+         the name will re-appear in the text box.</i>
+      <br/>
+      <br/>
+      <netui:form action="postOutputForm">
+          <netui:textBox dataSource="actionForm.name"/><br/>
+          <br/>
+          <netui:button value="Submit"/>
+      </netui:form>
+  </netui-template:section>
+</netui-template:template>
\ No newline at end of file

Added: incubator/beehive/trunk/samples/netui-samples/ui/formposting/validatedForm.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/ui/formposting/validatedForm.jsp?rev=178255&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/ui/formposting/validatedForm.jsp (added)
+++ incubator/beehive/trunk/samples/netui-samples/ui/formposting/validatedForm.jsp Tue May 24 12:31:21 2005
@@ -0,0 +1,46 @@
+<%--
+   Copyright 2004-2005 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:$
+--%>
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0" prefix="netui-data"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-template-1.0" prefix="netui-template"%>
+
+<netui-template:template templatePage="/resources/template/template.jsp">
+  <netui-template:setAttribute name="samTitle" value="Basic Form"/>
+  <netui-template:section name="main">
+      <div style="width:40%;">
+      <i>
+      Enter a name in this text box and click the Submit button to POST the value to the
+      server.  This form uses a Page Flow validationErrorForward annotation on the
+      postValidatedForm action to indicate that the form should be validated.  To pass
+      validation, enter "Frank" in the text box; otherwise, a validation error message
+      will be reported.  Once the form has been submitted, the name will re-appear in
+      this text box.
+      </i>
+      <br/>
+      <br/>
+      </div>
+      <div>
+      <netui:form action="postValidatedForm">
+          <netui:textBox dataSource="actionForm.name"/>&nbsp;&nbsp;<netui:error key="name"/><br/>
+          <br/>
+          <netui:button value="Submit"/>
+      </netui:form>
+      </div>
+  </netui-template:section>
+</netui-template:template>
\ No newline at end of file