You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/02/22 13:02:14 UTC

git commit: ISIS-351: services in applib, redirect to error page

Updated Branches:
  refs/heads/master e58012de1 -> b2b72fe09


ISIS-351: services in applib, redirect to error page

* added ExceptionRecognizer interface in applib, along with various helper implementations
* enhanced ServicesInjector (in core) to support multiple services of given type
* enhanced Wicket's ErrorPage to also render simple messages (ie suppress stacktrace for recognized exceptions)
* hooked WebRequestCycleForIsis to look for ExceptionRecognizers and redirect to ErrorPage accordingly
* provided implementations within the JDO object store
* updated ToDo app to demonstrate
* fixed rendering of select2 drop-down choices in Wicket viewer


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/b2b72fe0
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/b2b72fe0
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/b2b72fe0

Branch: refs/heads/master
Commit: b2b72fe091d954a00688d99767ffec2dba35b3ca
Parents: e58012d
Author: Dan Haywood <da...@apache.org>
Authored: Fri Feb 22 11:42:30 2013 +0000
Committer: Dan Haywood <da...@apache.org>
Committed: Fri Feb 22 11:42:30 2013 +0000

----------------------------------------------------------------------
 ...eptionRecognizerCompositeForJdoObjectStore.java |   43 ++++++++
 ...xceptionRecognizerForJDODataStoreException.java |   31 ++++++
 ...orSQLIntegrityConstraintViolationException.java |   30 ++++++
 .../integration/wicket/WebRequestCycleForIsis.java |   29 +++++-
 .../valuechoices/ValueChoicesSelect2Panel.html     |    2 +-
 .../valuechoices/ValueChoicesSelect2Panel.java     |    2 +-
 .../viewer/wicket/ui/pages/error/ErrorPage.css     |    7 +-
 .../viewer/wicket/ui/pages/error/ErrorPage.html    |   31 +++---
 .../viewer/wicket/ui/pages/error/ErrorPage.java    |   47 +++++++--
 .../services/exceprecog/ExceptionRecognizer.java   |   58 ++++++++++
 .../exceprecog/ExceptionRecognizerAbstract.java    |   57 ++++++++++
 .../exceprecog/ExceptionRecognizerComposite.java   |   82 +++++++++++++++
 .../exceprecog/ExceptionRecognizerDelegating.java  |   39 +++++++
 .../exceprecog/ExceptionRecognizerForType.java     |   56 ++++++++++
 .../exceprecog/ExceptionRecognizerGeneral.java     |   64 +++++++++++
 .../services/exceprecog/RecognizedException.java   |   43 ++++++++
 .../ExceptionRecognizerCompositeTest.java          |   54 ++++++++++
 .../exceprecog/ExceptionRecognizerForTypeTest.java |   54 ++++++++++
 .../exceprecog/ExceptionRecognizerGeneralTest.java |   49 +++++++++
 .../metamodel/runtimecontext/ServicesInjector.java |   25 +++++
 .../noruntime/RuntimeContextNoRuntime.java         |   11 ++-
 .../services/ServicesInjectorDefault.java          |   23 +++--
 .../metamodel/services/ServicesInjectorSpi.java    |    2 +
 .../container/DomainObjectContainerDefault.java    |   29 +++++-
 ...omainObjectContainerDefaultTest_recognizes.java |   49 +++++++++
 .../internal/RuntimeContextFromSession.java        |    6 +
 .../dom/src/main/java/dom/todo/ToDoItem.java       |    2 +-
 .../src/main/webapp/WEB-INF/isis.properties        |    3 +-
 28 files changed, 886 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerCompositeForJdoObjectStore.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerCompositeForJdoObjectStore.java b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerCompositeForJdoObjectStore.java
new file mode 100644
index 0000000..ed88c30
--- /dev/null
+++ b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerCompositeForJdoObjectStore.java
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.objectstore.jdo.applib.service.exceprecog;
+
+import org.apache.isis.applib.annotation.Hidden;
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerComposite;
+
+/**
+ * Convenience implementation of the {@link ExceptionRecognizer} domain service that
+ * recognizes a number of common and non-fatal exceptions (such as unique constraint
+ * violations).
+ * 
+ * <p>
+ * If using the JDO Object store, either register in <tt>isis.properties</tt>, or
+ * compose your own, out of the underlying more fine-grained {@link ExceptionRecognizer} implementations. 
+ */
+@Hidden
+public class ExceptionRecognizerCompositeForJdoObjectStore extends ExceptionRecognizerComposite {
+    
+    public ExceptionRecognizerCompositeForJdoObjectStore() {
+        // most specific ones first
+        add(new ExceptionRecognizerForSQLIntegrityConstraintViolationException());
+        add(new ExceptionRecognizerForJDODataStoreException());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java
new file mode 100644
index 0000000..94d9381
--- /dev/null
+++ b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForJDODataStoreException.java
@@ -0,0 +1,31 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.objectstore.jdo.applib.service.exceprecog;
+
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerForType;
+
+public class ExceptionRecognizerForJDODataStoreException extends ExceptionRecognizerForType {
+
+    public ExceptionRecognizerForJDODataStoreException() {
+        super(javax.jdo.JDODataStoreException.class, 
+            prefix("Unable to save changes.  " +
+            	   "Does similar data already exist, or has referenced data been deleted?"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForSQLIntegrityConstraintViolationException.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForSQLIntegrityConstraintViolationException.java b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForSQLIntegrityConstraintViolationException.java
new file mode 100644
index 0000000..934eaf6
--- /dev/null
+++ b/component/objectstore/jdo/jdo-applib/src/main/java/org/apache/isis/objectstore/jdo/applib/service/exceprecog/ExceptionRecognizerForSQLIntegrityConstraintViolationException.java
@@ -0,0 +1,30 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.objectstore.jdo.applib.service.exceprecog;
+
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerForType;
+
+public class ExceptionRecognizerForSQLIntegrityConstraintViolationException extends ExceptionRecognizerForType {
+
+    public ExceptionRecognizerForSQLIntegrityConstraintViolationException() {
+        super(java.sql.SQLIntegrityConstraintViolationException.class, 
+                prefix("Data already exists"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/viewer/wicket/impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java b/component/viewer/wicket/impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
index debf3ff..e0aabb3 100644
--- a/component/viewer/wicket/impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
+++ b/component/viewer/wicket/impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
@@ -19,7 +19,13 @@
 
 package org.apache.isis.viewer.wicket.viewer.integration.wicket;
 
+import java.util.List;
+
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerComposite;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.runtimecontext.ServicesInjector;
+import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
 import org.apache.isis.core.runtime.system.context.IsisContext;
 import org.apache.isis.core.runtime.system.session.IsisSession;
 import org.apache.isis.core.runtime.system.transaction.IsisTransaction;
@@ -88,7 +94,24 @@ public class WebRequestCycleForIsis /*extends WebRequestCycle*/ extends Abstract
 
     @Override
     public IRequestHandler onException(RequestCycle cycle, Exception ex) {
-        return new RenderPageRequestHandler(new PageProvider(new ErrorPage(ex)));
+        List<ExceptionRecognizer> exceptionRecognizers = getServicesInjector().lookupServices(ExceptionRecognizer.class);
+        String message = new ExceptionRecognizerComposite(exceptionRecognizers).recognize(ex);
+        final ErrorPage page = message != null ? new ErrorPage(message) : new ErrorPage(ex);
+        
+        return new RenderPageRequestHandler(new PageProvider(page));
+    }
+
+
+    
+    ///////////////////////////////////////////////////////////////
+    // Dependencies (from context)
+    ///////////////////////////////////////////////////////////////
+    
+    /**
+     * Factored out so can be overridden in testing.
+     */
+    protected ServicesInjector getServicesInjector() {
+        return IsisContext.getPersistenceSession().getServicesInjector();
     }
     
     /**
@@ -98,7 +121,9 @@ public class WebRequestCycleForIsis /*extends WebRequestCycle*/ extends Abstract
         return IsisContext.getInstance();
     }
 
-
+    /**
+     * Factored out so can be overridden in testing.
+     */
     protected IsisTransactionManager getTransactionManager() {
         return IsisContext.getTransactionManager();
     }

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.html
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.html b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.html
index eaccb59..5beab23 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.html
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.html
@@ -35,11 +35,11 @@
 					<span wicket:id="scalarName" class="scalarName">[Label text]</span>
 	      			<span class="scalarValue">
 	      				<input wicket:id="valueId" type="hidden" class="choices" />
+              			<span wicket:id="feedback"></span>
 					</span>
 				</label>
 			
 				<label wicket:id="scalarIfCompact"></label>
-      			<span wicket:id="feedback"></span>
 				
 			</div>
 		</wicket:panel>

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.java
index d5461a3..c268e7d 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/valuechoices/ValueChoicesSelect2Panel.java
@@ -84,7 +84,7 @@ public class ValueChoicesSelect2Panel extends ScalarPanelAbstract { // ScalarPan
         }
         addOrReplace(labelIfRegular);
 
-        addOrReplace(new ComponentFeedbackPanel(ID_FEEDBACK, valueField));
+        labelIfRegular.addOrReplace(new ComponentFeedbackPanel(ID_FEEDBACK, valueField));
         return labelIfRegular;
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.css
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.css b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.css
index dc92499..b8d0b98 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.css
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.css
@@ -18,13 +18,14 @@
  */
 
 
-.errorPage {
+.errorPage .errorInfo {
     margin-left: 50px;
     margin-right: 50px;
-    margin-top: 50px;
+    padding-top: 50px;
 }
 
-.errorPage #message {
+
+.errorPage .mainMessage {
     background:#FFFFFF;
     border-radius:4px;
     -moz-border-radius:4px;

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.html
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.html b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.html
index fc5f630..6808ef1 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.html
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.html
@@ -30,19 +30,24 @@
 	<body>
 		<wicket:extend>
 			<div class="errorPage">
-                <span id="message">Sorry, an unexpected error occurred.</span>
-                <div class="errorDetail">
-                    <div class="heading"><span>Show detail</span></div>
-                    <div class="content">
-                        <div class="exceptionMessage">
-                            <h3>Message:</h3>
-                            <p wicket:id="message">Message goes here</p>
-                        </div>
-                        <div class="exceptionStackTrace">
-                            <h3>Stack trace:</h3>
-                            <ul>
-                                <li wicket:id="detail"><span wicket:id="line">line</span></li>
-                            </ul>
+                <div wicket:id="breadcrumbs"/>
+                <div class="errorInfo clear">
+                    <span wicket:id="mainMessage" class="mainMessage">[main message text]</span>
+                    <div class="errorDetail" wicket:id="exceptionDetail">
+                        <div class="heading"><span>Show detail</span></div>
+                        <div class="content">
+                            <div class="exceptionMessage">
+                                <h3>Message:</h3>
+                                <p wicket:id="exceptionMessage">[exception message]</p>
+                            </div>
+                            <div class="exceptionStackTrace">
+                                <h3>Stack trace:</h3>
+                                <ul>
+                                    <li wicket:id="stackTraceElement">
+                                        <span wicket:id="stackTraceElementLine">[stack trace element line]</span>
+                                    </li>
+                                </ul>
+                            </div>
                         </div>
                     </div>
                 </div>

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.java
index c306e96..1a8a0e4 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/error/ErrorPage.java
@@ -22,11 +22,12 @@ package org.apache.isis.viewer.wicket.ui.pages.error;
 import java.util.List;
 
 import org.apache.isis.viewer.wicket.ui.pages.PageAbstract;
+import org.apache.wicket.MarkupContainer;
 import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
 import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.head.CssReferenceHeaderItem;
 import org.apache.wicket.markup.head.IHeaderResponse;
 import org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem;
+import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.list.ListItem;
 import org.apache.wicket.markup.html.list.ListView;
@@ -44,9 +45,15 @@ public class ErrorPage extends PageAbstract {
 
     private static final long serialVersionUID = 1L;
 
-    private static final String ID_MESSAGE = "message";
-    private static final String ID_DETAIL = "detail";
-    private static final String ID_LINE = "line";
+    private static final String MAIN_MESSAGE_IF_NOT_RECOGNIZED = "Sorry, an unexpected error occurred.";
+    
+    private static final String ID_MAIN_MESSAGE = "mainMessage";
+    
+    private static final String ID_EXCEPTION_DETAIL = "exceptionDetail";
+    private static final String ID_EXCEPTION_MESSAGE = "exceptionMessage";
+    
+    private static final String ID_STACK_TRACE_ELEMENT = "stackTraceElement";
+    private static final String ID_LINE = "stackTraceElementLine";
 
     private static final JavaScriptResourceReference DIV_TOGGLE_JS = new JavaScriptResourceReference(ErrorPage.class, "div-toggle.js");
 
@@ -64,13 +71,35 @@ public class ErrorPage extends PageAbstract {
         }
     }
 
+    /**
+     * For recognized messages.
+     */
+    public ErrorPage(String message) {
+        this(message, null, null);
+    }
+
+
+    /**
+     * For non-recognized messages.
+     */
     public ErrorPage(Exception ex) {
+        this(MAIN_MESSAGE_IF_NOT_RECOGNIZED, ex.getMessage(), asStackTrace(ex));
+    }
+
+    private ErrorPage(String mainMessage, String exceptionMessage, List<Detail> stackTraceDetail) {
         super(new PageParameters());
-        add(new Label(ID_MESSAGE, ex.getMessage()));
         
-        add(new ListView<Detail>(ID_DETAIL, asStackTrace(ex)) {
-                private static final long serialVersionUID = 1L;
+        addBookmarkedPages();
 
+        add(new Label(ID_MAIN_MESSAGE, mainMessage).setEscapeModelStrings(false));
+        MarkupContainer container = new WebMarkupContainer(ID_EXCEPTION_DETAIL);
+        add(container);
+        
+        if(exceptionMessage != null) {
+            container.add(new Label(ID_EXCEPTION_MESSAGE, exceptionMessage));
+            container.add(new ListView<Detail>(ID_STACK_TRACE_ELEMENT, stackTraceDetail) {
+                private static final long serialVersionUID = 1L;
+                
                 @Override
                 protected void populateItem(ListItem<Detail> item) {
                     final Detail detail = item.getModelObject();
@@ -79,6 +108,10 @@ public class ErrorPage extends PageAbstract {
                     item.add(label);
                 }
             });
+        } else {
+            // don't bother adding children, they won't ever be rendered.
+            container.setVisible(false);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizer.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizer.java b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizer.java
new file mode 100644
index 0000000..1cbbd66
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizer.java
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.applib.services.exceprecog;
+
+
+/**
+ * Domain service to (attempt) to recognize certain
+ * exceptions, and return user-friendly messages instead.
+ * 
+ * <p>
+ * Rather than redirecting to a general-purpose error page,
+ * the message (corresponding to the recognized exception) is rendered
+ * as a regular validation message. 
+ * 
+ * <p>
+ * More than one implementation of {@link ExceptionRecognizer} can
+ * be registered; they will all be consulted (in the order specified in
+ * <tt>isis.properties</tt>) to determine if they recognize the exception.
+ * The message returned by the first service recognizing the exception is
+ * used. 
+ * 
+ * <p>
+ * The Isis framework also provides a default implementation of this
+ * service that recognizes any {@link RecognizedException}, simply returning
+ * the exception's {@link RecognizedException#getMessage() message}.  This
+ * allows any component or domain object to throw this exception with
+ * the knowledge that it will be handled appropriately.
+ * 
+ * <p>
+ * Initially introduced for the Wicket viewer; check the documentation
+ * of other viewers to determine whether they also support this service.
+ */
+public interface ExceptionRecognizer {
+
+    /**
+     * (Attempt to) recognize the exception and return a user-friendly
+     * message to render instead.
+     * 
+     * @return user-friendly message to render, or <tt>null</tt> otherwise.
+     */
+    public String recognize(Throwable ex);
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerAbstract.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerAbstract.java b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerAbstract.java
new file mode 100644
index 0000000..eb539f7
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerAbstract.java
@@ -0,0 +1,57 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.applib.services.exceprecog;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+
+/**
+ * Convenience implementation of {@link ExceptionRecognizer} that provides some
+ * utility methods to subclasses.
+ */
+public abstract class ExceptionRecognizerAbstract implements ExceptionRecognizer {
+
+    /**
+     * Convenience for subclass implementations that always return a fixed message.
+     */
+    protected static Function<String, String> constant(final String message) {
+        return new Function<String, String>() {
+
+            @Override
+            public String apply(String input) {
+                return message;
+            }
+        };
+    }
+
+    /**
+     * Convenience for subclass implementations that always prefixes the exception message
+     * with the supplied text
+     */
+    protected static Function<String, String> prefix(final String prefix) {
+        return new Function<String, String>() {
+
+            @Override
+            public String apply(String input) {
+                return prefix + "<br/><br/>" + input;
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerComposite.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerComposite.java b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerComposite.java
new file mode 100644
index 0000000..35975ef
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerComposite.java
@@ -0,0 +1,82 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.applib.services.exceprecog;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.isis.applib.annotation.Hidden;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Convenience implementation of {@link ExceptionRecognizer} that loops through a list of
+ * {@link #add(ExceptionRecognizer) registered} services.
+ * 
+ * <p>
+ * Note that the framework <i>does</i> allow multiple {@link ExceptionRecognizer service}s
+ * to be registered in <tt>isis.properties</tt>, and each will be consulted in turn.  Therefore
+ * it is not necessary to use this class to register more than one such service.  However,
+ * it may be useful to use to treat a group of similar exceptions as a single unit.  For example,
+ * the <i>JDO object store</i> (in its applib) provides a set of {@link ExceptionRecognizer} to
+ * recognize various types of constraint violations.  These are grouped together as a single
+ * set through the use of this class.
+ */
+@Hidden
+public class ExceptionRecognizerComposite implements ExceptionRecognizer {
+
+    private final List<ExceptionRecognizer> services = Lists.newArrayList();
+
+    public ExceptionRecognizerComposite(ExceptionRecognizer... exceptionRecognizers) {
+        this(Arrays.asList(exceptionRecognizers));
+    }
+    
+    public ExceptionRecognizerComposite(List<ExceptionRecognizer> exceptionRecognizers) {
+        for (ExceptionRecognizer er : exceptionRecognizers) {
+            add(er);
+        }
+    }
+
+    /**
+     * Register an {@link ExceptionRecognizer} to be consulted when
+     * {@link #recognize(Exception)} is called.
+     * 
+     * <p>
+     * The most specific {@link ExceptionRecognizer recognizer}s should be registered
+     * before the more general ones.  See the <i>JDO object store</i> applib for
+     * an example.
+     */
+    public void add(ExceptionRecognizer ers) {
+        services.add(ers);
+    }
+    
+    /**
+     * Returns the non-<tt>null</tt> message of the first {@link #add(ExceptionRecognizer) add}ed 
+     * {@link ExceptionRecognizer service} that recognizes the exception. 
+     */
+    public String recognize(Throwable ex) {
+        for (ExceptionRecognizer ers : services) {
+            String message = ers.recognize(ex);
+            if(message != null) {
+                return message;
+            }
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerDelegating.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerDelegating.java b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerDelegating.java
new file mode 100644
index 0000000..e13ae45
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerDelegating.java
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.applib.services.exceprecog;
+
+
+/**
+ * Convenience implementation of {@link ExceptionRecognizer} that simply
+ * delegates to an underlying implementation.
+ */
+public abstract class ExceptionRecognizerDelegating extends ExceptionRecognizerAbstract {
+
+    private final ExceptionRecognizer delegate;
+
+    public ExceptionRecognizerDelegating(ExceptionRecognizer delegate) {
+        this.delegate = delegate;
+    }
+
+    @Override
+    public String recognize(Throwable ex) {
+        return delegate.recognize(ex);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
new file mode 100644
index 0000000..28f37fb
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.applib.services.exceprecog;
+
+import org.apache.isis.applib.annotation.Hidden;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Throwables;
+
+/**
+ * An specific implementation of {@link ExceptionRecognizer} that looks for an
+ * exception of the type provided in the constructor
+ * and, if found anywhere in the {@link Throwables#getCausalChain(Throwable) causal chain},
+ * then returns a non-null message indicating that the exception has been recognized.
+ * 
+ * <p>
+ * If a messaging-parsing {@link Function} is provided through the constructor,
+ * then the message can be altered.  Otherwise the exception's {@link Throwable#getMessage() message} is returned as-is.
+ */
+@Hidden
+public class ExceptionRecognizerForType extends ExceptionRecognizerDelegating {
+
+    private final static Predicate<Throwable> ofType(final Class<? extends Throwable> exceptionType) {
+        return new Predicate<Throwable>() {
+            @Override
+            public boolean apply(Throwable input) {
+                return exceptionType.isAssignableFrom(input.getClass());
+            }
+        };
+    }
+
+    public ExceptionRecognizerForType(final Class<? extends Exception> exceptionType, final Function<String,String> messageParser) {
+        super(new ExceptionRecognizerGeneral(ofType(exceptionType), messageParser));
+    }
+    
+    public ExceptionRecognizerForType(Class<? extends Exception> exceptionType) {
+        this(exceptionType, null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerGeneral.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerGeneral.java b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerGeneral.java
new file mode 100644
index 0000000..94df6b4
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerGeneral.java
@@ -0,0 +1,64 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.applib.services.exceprecog;
+
+import java.util.List;
+
+import org.apache.isis.applib.annotation.Hidden;
+
+import com.google.common.base.Function;
+import com.google.common.base.Functions;
+import com.google.common.base.Predicate;
+import com.google.common.base.Throwables;
+
+/**
+ * A general purpose implementation of {@link ExceptionRecognizer} that looks 
+ * exceptions meeting the {@link Predicate} supplied in the constructor
+ * and, if found anywhere in the {@link Throwables#getCausalChain(Throwable) causal chain},
+ * then returns a non-null message indicating that the exception has been recognized.
+ * 
+ * <p>
+ * If a messaging-parsing {@link Function} is provided through the constructor,
+ * then the message can be altered.  Otherwise the exception's {@link Throwable#getMessage() message} is returned as-is.
+ */
+@Hidden
+public class ExceptionRecognizerGeneral extends ExceptionRecognizerAbstract {
+
+    private final Predicate<Throwable> predicate;
+    private final Function<String,String> messageParser;
+
+    public ExceptionRecognizerGeneral(Predicate<Throwable> predicate, final Function<String,String> messageParser) {
+        this.predicate = predicate;
+        this.messageParser = messageParser != null? messageParser: Functions.<String>identity();
+    }
+
+    public ExceptionRecognizerGeneral(Predicate<Throwable> predicate) {
+        this(predicate, null);
+    }
+
+    public String recognize(Throwable ex) {
+        List<Throwable> causalChain = Throwables.getCausalChain(ex);
+        for (Throwable throwable : causalChain) {
+            if(predicate.apply(throwable)) {
+                return messageParser.apply(throwable.getMessage());
+            }
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/RecognizedException.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/RecognizedException.java b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/RecognizedException.java
new file mode 100644
index 0000000..2acce4f
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/exceprecog/RecognizedException.java
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.isis.applib.services.exceprecog;
+
+/**
+ * An exception that will be recognized by the framework
+ * and handled as a regular validation message.
+ * 
+ * <p>
+ * See {@link ExceptionRecognizer} for further
+ * discussion. 
+ * 
+ * @see ExceptionRecognizer
+ */
+public class RecognizedException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    public RecognizedException(String message, Throwable ex) {
+        super(message, ex);
+    }
+
+    public RecognizedException(String message) {
+        super(message);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerCompositeTest.java
----------------------------------------------------------------------
diff --git a/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerCompositeTest.java b/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerCompositeTest.java
new file mode 100644
index 0000000..bb764a7
--- /dev/null
+++ b/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerCompositeTest.java
@@ -0,0 +1,54 @@
+package org.apache.isis.applib.services.exceprecog;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ExceptionRecognizerCompositeTest {
+
+    private ExceptionRecognizerComposite composite;
+
+    static class FakeERS implements ExceptionRecognizer {
+        private String message;
+        public FakeERS(String message) {
+            this.message = message;
+        }
+        @Override
+        public String recognize(Throwable ex) {
+            return message;
+        }
+    }
+    
+    @Before
+    public void setUp() throws Exception {
+        composite = new ExceptionRecognizerComposite();
+    }
+    
+    @Test
+    public void whenEmpty() {
+        assertThat(composite.recognize(new RuntimeException()), is(nullValue()));
+    }
+
+    @Test
+    public void whenOne() {
+        composite.add(new FakeERS("one"));
+        assertThat(composite.recognize(new RuntimeException()), is("one"));
+    }
+
+    @Test
+    public void whenNullThenOne() {
+        composite.add(new FakeERS(null));
+        composite.add(new FakeERS("one"));
+        assertThat(composite.recognize(new RuntimeException()), is("one"));
+    }
+
+    @Test
+    public void whenOneThenTwo() {
+        composite.add(new FakeERS("one"));
+        composite.add(new FakeERS("two"));
+        assertThat(composite.recognize(new RuntimeException()), is("one"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForTypeTest.java
----------------------------------------------------------------------
diff --git a/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForTypeTest.java b/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForTypeTest.java
new file mode 100644
index 0000000..0968838
--- /dev/null
+++ b/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForTypeTest.java
@@ -0,0 +1,54 @@
+package org.apache.isis.applib.services.exceprecog;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+import com.google.common.base.Function;
+
+public class ExceptionRecognizerForTypeTest {
+
+    private ExceptionRecognizerForType ersForType;
+
+    static class FooException extends Exception {
+        private static final long serialVersionUID = 1L;
+        public FooException() {
+            super("foo");
+        }
+        
+    }
+    static class BarException extends Exception {
+        private static final long serialVersionUID = 1L;
+        public BarException() {
+            super("bar");
+        }
+    }
+    
+    private Function<String,String> prepend = new Function<String, String>() {
+        @Override
+        public String apply(String input) {
+            return "pre: " + input;
+        }
+    };
+
+    @Test
+    public void whenRecognized() {
+        ersForType = new ExceptionRecognizerForType(FooException.class);
+        assertThat(ersForType.recognize(new FooException()), is("foo"));
+    }
+
+    @Test
+    public void whenDoesNotRecognize() {
+        ersForType = new ExceptionRecognizerForType(FooException.class);
+        assertThat(ersForType.recognize(new BarException()), is(nullValue()));
+    }
+
+    @Test
+    public void whenRecognizedWithMessageParser() {
+        ersForType = new ExceptionRecognizerForType(FooException.class, prepend);
+        assertThat(ersForType.recognize(new FooException()), is("pre: foo"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerGeneralTest.java
----------------------------------------------------------------------
diff --git a/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerGeneralTest.java b/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerGeneralTest.java
new file mode 100644
index 0000000..614a35c
--- /dev/null
+++ b/core/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerGeneralTest.java
@@ -0,0 +1,49 @@
+package org.apache.isis.applib.services.exceprecog;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicates;
+
+public class ExceptionRecognizerGeneralTest {
+
+    private ExceptionRecognizerGeneral ersGeneral;
+
+    static class FooException extends Exception {
+        private static final long serialVersionUID = 1L;
+        public FooException() {
+            super("foo");
+        }
+    }
+    
+    private Function<String,String> prepend = new Function<String, String>() {
+        @Override
+        public String apply(String input) {
+            return "pre: " + input;
+        }
+    };
+    
+    
+    @Test
+    public void whenRecognized() {
+        ersGeneral = new ExceptionRecognizerGeneral(Predicates.<Throwable>alwaysTrue());
+        assertThat(ersGeneral.recognize(new FooException()), is("foo"));
+    }
+
+    @Test
+    public void whenDoesNotRecognize() {
+        ersGeneral = new ExceptionRecognizerGeneral(Predicates.<Throwable>alwaysFalse());
+        assertThat(ersGeneral.recognize(new FooException()), is(nullValue()));
+    }
+
+    @Test
+    public void whenRecognizedWithMessageParser() {
+        ersGeneral = new ExceptionRecognizerGeneral(Predicates.<Throwable>alwaysTrue(), prepend);
+        assertThat(ersGeneral.recognize(new FooException()), is("pre: foo"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/ServicesInjector.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/ServicesInjector.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/ServicesInjector.java
index 71f88fd..bd17f9e 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/ServicesInjector.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/ServicesInjector.java
@@ -18,6 +18,8 @@ package org.apache.isis.core.metamodel.runtimecontext;
 
 import java.util.List;
 
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
+import org.apache.isis.applib.services.publish.PublishingService;
 import org.apache.isis.core.commons.components.Injectable;
 
 public interface ServicesInjector extends Injectable {
@@ -36,5 +38,28 @@ public interface ServicesInjector extends Injectable {
      */
     void injectServicesInto(List<Object> objects);
 
+    /**
+     * Returns the first registered domain service implementing the requested type.
+     * 
+     * <p>
+     * Typically there will only ever be one domain service implementing a given type,
+     * (eg {@link PublishingService}), but for some services there can be more than one
+     * (eg {@link ExceptionRecognizer}).
+     * 
+     * @see #lookupServices(Class)
+     */
     <T> T lookupService(Class<T> serviceClass);
+    
+    /**
+     * Returns all domain services implementing the requested type, in the order
+     * that they were registered in <tt>isis.properties</tt>.
+     * 
+     * <p>
+     * Typically there will only ever be one domain service implementing a given type,
+     * (eg {@link PublishingService}), but for some services there can be more than one
+     * (eg {@link ExceptionRecognizer}).
+     * 
+     * @see #lookupService(Class)
+     */
+    <T> List<T> lookupServices(Class<T> serviceClass);
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/noruntime/RuntimeContextNoRuntime.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/noruntime/RuntimeContextNoRuntime.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/noruntime/RuntimeContextNoRuntime.java
index de232e9..da87335 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/noruntime/RuntimeContextNoRuntime.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/runtimecontext/noruntime/RuntimeContextNoRuntime.java
@@ -58,7 +58,7 @@ import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
 public class RuntimeContextNoRuntime extends RuntimeContextAbstract {
 
     private final DeploymentCategory deploymentCategory;
-    private final ServicesInjector dependencyInjector;
+    private final ServicesInjector servicesInjector;
     private final AuthenticationSessionProviderAbstract authenticationSessionProvider;
     private final AdapterManager adapterManager;
     private final ObjectInstantiatorAbstract objectInstantiator;
@@ -76,7 +76,7 @@ public class RuntimeContextNoRuntime extends RuntimeContextAbstract {
         this.deploymentCategory = deploymentCategory;
         // Unlike most of the methods in this implementation, does nothing
         // (because this will always be called, even in a no-runtime context).
-        dependencyInjector = new ServicesInjector() {
+        servicesInjector = new ServicesInjector() {
             @Override
             public void injectServicesInto(final Object domainObject) {
             }
@@ -93,6 +93,11 @@ public class RuntimeContextNoRuntime extends RuntimeContextAbstract {
             @Override
             public void injectInto(Object candidate) {
             }
+
+            @Override
+            public <T> List<T> lookupServices(Class<T> serviceClass) {
+                return null;
+            }
         };
         authenticationSessionProvider = new AuthenticationSessionProviderAbstract() {
             @Override
@@ -308,7 +313,7 @@ public class RuntimeContextNoRuntime extends RuntimeContextAbstract {
 
     @Override
     public ServicesInjector getDependencyInjector() {
-        return dependencyInjector;
+        return servicesInjector;
     }
 
     // ///////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java
index 387101b..46e047b 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java
@@ -31,6 +31,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
 import org.apache.isis.core.commons.ensure.Assert;
 import org.apache.isis.core.commons.lang.CastUtils;
 import org.apache.isis.core.commons.lang.ToString;
@@ -52,10 +53,10 @@ public class ServicesInjectorDefault implements ServicesInjectorSpi {
     private static final Logger LOG = Logger.getLogger(ServicesInjectorDefault.class);
 
     /**
-     * If no key, not yet searched for type; otherwise the {@link Optional} indicates
+     * If no key, not yet searched for type; otherwise the {@link List} indicates
      * whether a service was found.
      */
-    private final Map<Class<?>, Optional<Object>> servicesByType = Maps.newHashMap();
+    private final Map<Class<?>, List<Object>> servicesByType = Maps.newHashMap();
 
     private final List<Object> services = Lists.newArrayList();
     
@@ -220,19 +221,23 @@ public class ServicesInjectorDefault implements ServicesInjectorSpi {
 
     @Override
     public <T> T lookupService(Class<T> serviceClass) {
-        locateAndCache(services, serviceClass);
-        @SuppressWarnings("unchecked")
-        Optional<T> optionalService = (Optional<T>) servicesByType.get(serviceClass);
-        return optionalService.orNull();
+        List<T> services = lookupServices(serviceClass);
+        return !services.isEmpty() ? services.get(0) : null;
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> List<T> lookupServices(Class<T> serviceClass) {
+        locateAndCache(services, serviceClass);
+        return (List<T>) servicesByType.get(serviceClass);
+    };
+
     private void locateAndCache(List<Object> services, Class<?> serviceClass) {
         if(servicesByType.containsKey(serviceClass)) {
            return; 
         }
 
-        final Optional<Object> optionalService = Iterables.tryFind(services, ofType(serviceClass));
-        servicesByType.put(serviceClass, optionalService);
+        servicesByType.put(serviceClass, Lists.newArrayList(Iterables.filter(services, ofType(serviceClass))));
     }
 
     private static final Predicate<Object> ofType(final Class<?> cls) {
@@ -242,7 +247,7 @@ public class ServicesInjectorDefault implements ServicesInjectorSpi {
                 return cls.isAssignableFrom(input.getClass());
             }
         };
-    };
+    }
 
 
 

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorSpi.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorSpi.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorSpi.java
index 3b2f020..e598a2d 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorSpi.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorSpi.java
@@ -22,6 +22,7 @@ package org.apache.isis.core.metamodel.services;
 import java.util.List;
 
 import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
 import org.apache.isis.core.commons.components.ApplicationScopedComponent;
 import org.apache.isis.core.commons.components.Injectable;
 import org.apache.isis.core.commons.components.SessionScopedComponent;
@@ -76,4 +77,5 @@ public interface ServicesInjectorSpi extends ApplicationScopedComponent, Injecta
      */
     List<Object> getRegisteredServices();
 
+
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
index 87226a5..b65a121 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefault.java
@@ -30,6 +30,10 @@ import org.apache.isis.applib.query.Query;
 import org.apache.isis.applib.query.QueryFindAllInstances;
 import org.apache.isis.applib.security.RoleMemento;
 import org.apache.isis.applib.security.UserMemento;
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerForType;
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerGeneral;
+import org.apache.isis.applib.services.exceprecog.RecognizedException;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
 import org.apache.isis.core.commons.authentication.AuthenticationSessionProviderAware;
@@ -57,7 +61,7 @@ import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.SpecificationLoader;
 import org.apache.isis.core.metamodel.spec.SpecificationLoaderAware;
 
-public class DomainObjectContainerDefault implements DomainObjectContainer, QuerySubmitterAware, ObjectDirtierAware, DomainObjectServicesAware, ObjectPersistorAware, SpecificationLoaderAware, AuthenticationSessionProviderAware, AdapterManagerAware, LocalizationProviderAware {
+public class  DomainObjectContainerDefault implements DomainObjectContainer, QuerySubmitterAware, ObjectDirtierAware, DomainObjectServicesAware, ObjectPersistorAware, SpecificationLoaderAware, AuthenticationSessionProviderAware, AdapterManagerAware, LocalizationProviderAware, ExceptionRecognizer {
 
     private ObjectDirtier objectDirtier;
     private ObjectPersistor objectPersistor;
@@ -432,6 +436,27 @@ public class DomainObjectContainerDefault implements DomainObjectContainer, Quer
         return instances.size() == 0 ? null : instances.get(0);
     }
 
+    
+    ///////////////////////////////////////////////////////////////
+    // ExceptionRecognitionService
+    ///////////////////////////////////////////////////////////////
+
+    private final ExceptionRecognizer recogService = new ExceptionRecognizerForType(RecognizedException.class);
+    
+    /**
+     * Framework-provided implementation of {@link ExceptionRecognizer},
+     * which will automatically recognize any {@link RecognizedException}.
+     */
+    @Override
+    public String recognize(Throwable ex) {
+        return getRecogService().recognize(ex);
+    }
+    
+    ExceptionRecognizer getRecogService() {
+        return recogService;
+    }
+
+    
     // //////////////////////////////////////////////////////////////////
     // Dependencies
     // //////////////////////////////////////////////////////////////////
@@ -504,4 +529,6 @@ public class DomainObjectContainerDefault implements DomainObjectContainer, Quer
         this.localizationProvider = localizationProvider;
     }
 
+    
+
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefaultTest_recognizes.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefaultTest_recognizes.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefaultTest_recognizes.java
new file mode 100644
index 0000000..9def9ff
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/services/container/DomainObjectContainerDefaultTest_recognizes.java
@@ -0,0 +1,49 @@
+package org.apache.isis.core.metamodel.services.container;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
+import org.apache.isis.applib.services.exceprecog.RecognizedException;
+import org.apache.isis.core.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class DomainObjectContainerDefaultTest_recognizes {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+    @Mock
+    private ExceptionRecognizer mockERS;
+
+    private RecognizedException ex;
+    
+    private DomainObjectContainerDefault container;
+    
+    @Before
+    public void setUp() throws Exception {
+        ex = new RecognizedException("foo");
+        container = new DomainObjectContainerDefault() {
+            @Override
+            ExceptionRecognizer getRecogService() {
+                return mockERS;
+            }
+        };
+    }
+    
+    @Test
+    public void delegates() throws Exception {
+        context.checking(new Expectations() {
+            {
+                one(mockERS).recognize(ex);
+            }
+        });
+        container.recognize(ex);
+    }
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/internal/RuntimeContextFromSession.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/internal/RuntimeContextFromSession.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/internal/RuntimeContextFromSession.java
index 24d9316..b05085d 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/internal/RuntimeContextFromSession.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/persistence/internal/RuntimeContextFromSession.java
@@ -280,12 +280,18 @@ public class RuntimeContextFromSession extends RuntimeContextAbstract {
             }
 
             @Override
+            public <T> List<T> lookupServices(Class<T> serviceClass) {
+                return getPersistenceSession().getServicesInjector().lookupServices(serviceClass);
+            }
+            
+            @Override
             public void injectInto(Object candidate) {
                 if (ServicesInjectorAware.class.isAssignableFrom(candidate.getClass())) {
                     final ServicesInjectorAware cast = ServicesInjectorAware.class.cast(candidate);
                     cast.setServicesInjector(this);
                 }
             }
+
         };
         this.localizationProvider = new LocalizationProviderAbstract() {
 

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
index 07dd3fd..069dc1a 100644
--- a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
+++ b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
@@ -109,7 +109,7 @@ public class ToDoItem implements Comparable<ToDoItem> /*, Locatable*/ { // GMAP3
     // {{ Description
     private String description;
 
-    @javax.jdo.annotations.Unique
+    @javax.jdo.annotations.Unique(name="ToDoItem_description_must_be_unique")
     @RegEx(validation = "\\w[@&:\\-\\,\\.\\+ \\w]*")
     // words, spaces and selected punctuation
     @MemberOrder(sequence = "1")

http://git-wip-us.apache.org/repos/asf/isis/blob/b2b72fe0/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
index a013d8b..c8de80a 100644
--- a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
+++ b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
@@ -164,7 +164,8 @@ isis.services = objstore.jdo.todo.ToDoItemsJdo,\
                 fixture.todo.ToDoItemsFixturesService,\
                 dom.audit.AuditServiceDemo,\
                 org.apache.isis.applib.services.publish.PublishingService$Stderr,\
-                org.apache.isis.viewer.restfulobjects.rendering.eventserializer.RestfulObjectsSpecEventSerializer
+                org.apache.isis.viewer.restfulobjects.rendering.eventserializer.RestfulObjectsSpecEventSerializer,\
+                org.apache.isis.objectstore.jdo.applib.service.exceprecog.ExceptionRecognizerCompositeForJdoObjectStore
 
 # Specify the (optional) test fixtures
 #