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/05/25 06:44:20 UTC
svn commit: r178367 - in /incubator/beehive/trunk/samples/netui-samples: ./
WEB-INF/src/org/apache/beehive/samples/netui/resources/exceptions/
exceptions/ nesting/ validation/
Author: rich
Date: Tue May 24 21:44:18 2005
New Revision: 178367
URL: http://svn.apache.org/viewcvs?rev=178367&view=rev
Log:
Added a feature sample for declarative exception handling.
tests: build.dist (WinXP)
BB (and run.tests): self (linux)
Added:
incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/exceptions/
incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/exceptions/messages.properties (with props)
incubator/beehive/trunk/samples/netui-samples/exceptions/
incubator/beehive/trunk/samples/netui-samples/exceptions/Controller.java (with props)
incubator/beehive/trunk/samples/netui-samples/exceptions/caught.jsp (with props)
incubator/beehive/trunk/samples/netui-samples/exceptions/index.jsp (with props)
Modified:
incubator/beehive/trunk/samples/netui-samples/index.jsp
incubator/beehive/trunk/samples/netui-samples/nesting/Controller.java
incubator/beehive/trunk/samples/netui-samples/validation/Controller.java
Added: incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/exceptions/messages.properties
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/exceptions/messages.properties?rev=178367&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/exceptions/messages.properties (added)
+++ incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/exceptions/messages.properties Tue May 24 21:44:18 2005
@@ -0,0 +1,6 @@
+# Messages for the /exceptions/Controller.java example
+
+exceptions.Controller$Exception1=\
+This is a custom message for Exception1, in message key exceptions.Controller$Exception1.
+
+messages.exception2=This is a custom message for Exception2, in message key messages.exception2.
Propchange: incubator/beehive/trunk/samples/netui-samples/WEB-INF/src/org/apache/beehive/samples/netui/resources/exceptions/messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/beehive/trunk/samples/netui-samples/exceptions/Controller.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/exceptions/Controller.java?rev=178367&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/exceptions/Controller.java (added)
+++ incubator/beehive/trunk/samples/netui-samples/exceptions/Controller.java Tue May 24 21:44:18 2005
@@ -0,0 +1,108 @@
+/*
+ * 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 exceptions;
+
+import java.io.Serializable;
+
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.PageFlowController;
+
+
+/**
+ * Demonstration of Page Flow declarative exception handling.
+ */
+@Jpf.Controller(
+ simpleActions={
+ @Jpf.SimpleAction(name="begin",path="index.jsp")
+ },
+ catches={
+ // Catch Exception1, and simply forward to caught.jsp.
+ @Jpf.Catch(type=Controller.Exception1.class, path="caught.jsp"),
+
+ // Catch Exception2, and specify that the error message should come from key
+ // messages.exception2.
+ @Jpf.Catch(
+ type=Controller.Exception2.class,
+ path="caught.jsp",
+ messageKey="messages.exception2"
+ ),
+
+ // Catch BaseException (which will catch Exception3), and specify a hardcoded message
+ // (which can contain JSP 2.0-style expressions). Handle the exception with the handleIt()
+ // method.
+ @Jpf.Catch(
+ type=Controller.BaseException.class,
+ method="handleIt",
+ message="This is a hardcoded message from page flow ${pageFlow.URI}."
+ )
+ },
+ messageBundles={
+ @Jpf.MessageBundle(
+ bundlePath="org.apache.beehive.samples.netui.resources.exceptions.messages"
+ )
+ }
+)
+public class Controller extends PageFlowController
+{
+ public static abstract class BaseException
+ extends Exception
+ {
+ public String getMessage()
+ {
+ return "This is the result of calling getMessage() on the exception.";
+ }
+ }
+
+ public class Exception1 extends BaseException {}
+ public class Exception2 extends BaseException {}
+ public class Exception3 extends BaseException {}
+
+ @Jpf.Action()
+ public Forward throwException1()
+ throws Exception1
+ {
+ // Note that there is no need to catch Exception1 *inside* this action method; just put
+ // Exception1 in the 'throws' for the method.
+ throw new Exception1();
+ }
+
+ @Jpf.Action()
+ public Forward throwException2()
+ throws Exception2
+ {
+ throw new Exception2();
+ }
+
+ @Jpf.Action()
+ public Forward throwException3()
+ throws Exception3
+ {
+ throw new Exception3();
+ }
+
+ @Jpf.ExceptionHandler(
+ forwards={
+ @Jpf.Forward(name="caughtPage", path="caught.jsp")
+ }
+ )
+ public Forward handleIt(BaseException ex, String actionName, String message, Object formBean)
+ {
+ return new Forward("caughtPage");
+ }
+}
Propchange: incubator/beehive/trunk/samples/netui-samples/exceptions/Controller.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/beehive/trunk/samples/netui-samples/exceptions/caught.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/exceptions/caught.jsp?rev=178367&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/exceptions/caught.jsp (added)
+++ incubator/beehive/trunk/samples/netui-samples/exceptions/caught.jsp Tue May 24 21:44:18 2005
@@ -0,0 +1,45 @@
+<%--
+ 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 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="Declarative Exception Handling"/>
+
+ <netui-template:section name="main">
+ The <code>netui:errors</code> (or <code>netui:error</code>, with the appropriate
+ <code>key</code>) tag can print custom error messages for exceptions, which are found in
+ message keys that are the exception class names, or which are overridden by the
+ <code>@Jpf.Catch</code> annotations in the page flow:
+ <blockquote>
+ <b><netui:errors/></b>
+ </blockquote>
+ <br/>
+ The <code>netui:exceptions</code> tag can print the result of <code>getMessage</code> on
+ the exception, and/or the exception stack trace:
+ <blockquote>
+ <b><netui:exceptions showMessage="true" showStackTrace="false"/></b>
+ </blockquote>
+ <br/>
+ <netui:anchor action="begin">try again</netui:anchor>
+ </netui-template:section>
+
+</netui-template:template>
Propchange: incubator/beehive/trunk/samples/netui-samples/exceptions/caught.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/beehive/trunk/samples/netui-samples/exceptions/index.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/exceptions/index.jsp?rev=178367&view=auto
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/exceptions/index.jsp (added)
+++ incubator/beehive/trunk/samples/netui-samples/exceptions/index.jsp Tue May 24 21:44:18 2005
@@ -0,0 +1,36 @@
+<%--
+ 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 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="Declarative Exception Handling"/>
+
+ <netui-template:section name="main">
+ <netui:anchor action="throwException1">throw Exception1</netui:anchor>
+ <br/>
+ <netui:anchor action="throwException2">throw Exception2</netui:anchor>
+ <br/>
+ <netui:anchor action="throwException3">throw Exception3</netui:anchor>
+ <br/>
+ </netui-template:section>
+
+</netui-template:template>
Propchange: incubator/beehive/trunk/samples/netui-samples/exceptions/index.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/beehive/trunk/samples/netui-samples/index.jsp
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/index.jsp?rev=178367&r1=178366&r2=178367&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/index.jsp (original)
+++ incubator/beehive/trunk/samples/netui-samples/index.jsp Tue May 24 21:44:18 2005
@@ -31,6 +31,10 @@
<b>NetUI Page Flow Core</b>
<br/>
<dl>
+ <dt><netui:anchor href="exceptions/Controller.jpf" value="Exception Handling"/></dt>
+ <dd>Demonstrates Page Flow declarative exception handling.</dd>
+ </dl>
+ <dl>
<dt><netui:anchor href="loginexample/start/Controller.jpf" value="Login"/></dt>
<dd>Demonstrates defining your own LoginHandler, as well as nested page flows and Page Flow
inheritance.</dd>
@@ -54,11 +58,11 @@
<br/>
<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>
+ <dd>Demonstrates how to use a page flow and NetUI JSP tags to handle an HTML form POST.</dd>
</dl>
<dl>
<dt><netui:anchor href="ui/pageinput/Controller.jpf" value="Page Input"/></dt>
- <dd>Demonstrates how to use a Page Flow page inputs to pass data from an action to a JSP page.</dd>
+ <dd>Demonstrates how to use a page flow and page inputs to pass data from an action to a JSP page.</dd>
</dl>
<dl>
<dt><netui:anchor href="ui/resourcebinding/Controller.jpf" value="Message Resource Binding"/></dt>
@@ -79,7 +83,7 @@
</dl>
<dl>
<dt><netui:anchor href="ui/popup/Controller.jpf" value="Popup Window"/></dt>
- <dd>Demonstrates nested page flow shown in a popup window, with values passed back to the
+ <dd>Demonstrates a nested page flow shown in a popup window, with values passed back to the
original page flow.</dd>
</dl>
<dl>
Modified: incubator/beehive/trunk/samples/netui-samples/nesting/Controller.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/nesting/Controller.java?rev=178367&r1=178366&r2=178367&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/nesting/Controller.java (original)
+++ incubator/beehive/trunk/samples/netui-samples/nesting/Controller.java Tue May 24 21:44:18 2005
@@ -4,7 +4,9 @@
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
-
+/**
+ * Main page flow, which invokes a nested page flow and gets data back from it.
+ */
@Jpf.Controller(
simpleActions={
@Jpf.SimpleAction(name="begin", path="index.jsp"),
Modified: incubator/beehive/trunk/samples/netui-samples/validation/Controller.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/samples/netui-samples/validation/Controller.java?rev=178367&r1=178366&r2=178367&view=diff
==============================================================================
--- incubator/beehive/trunk/samples/netui-samples/validation/Controller.java (original)
+++ incubator/beehive/trunk/samples/netui-samples/validation/Controller.java Tue May 24 21:44:18 2005
@@ -24,6 +24,9 @@
import org.apache.beehive.netui.pageflow.PageFlowController;
+/**
+ * Demonstration of Page Flow declarative field validation.
+ */
@Jpf.Controller(
simpleActions={
@Jpf.SimpleAction(name="begin",path="index.jsp")