You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bu...@apache.org on 2014/01/28 02:49:22 UTC

svn commit: r895593 [5/7] - in /websites/staging/myfaces/trunk/content: ./ wiki/ wiki/asf-board-reports/ wiki/commons/ wiki/commons/user-guide/ wiki/core/ wiki/core/committer-and-pmc-guide/ wiki/core/committer-and-pmc-guide/myfaces-project-management/ ...

Added: websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/backend/resulting-nested-facescontext.html
==============================================================================
--- websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/backend/resulting-nested-facescontext.html (added)
+++ websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/backend/resulting-nested-facescontext.html Tue Jan 28 01:49:20 2014
@@ -0,0 +1,205 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>Resulting Nested FacesContext</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+
+    
+
+    
+    
+  </head>
+
+  <body>
+    <div id="page" class="container_16">
+      <div id="header" class="grid_8">
+        <img src="http://www.apache.org/images/feather-small.gif" alt="The Apache Software Foundation">
+        <h1>The Apache Software Foundation</h1>
+        <h2>Resulting Nested FacesContext</h2>
+      </div>
+      <div id="nav" class="grid_8">
+        <ul>
+          <!-- <li><a href="/" title="Welcome!">Home</a></li> -->
+          <li><a href="http://www.apache.org/foundation/" title="The Foundation">Foundation</a></li>
+          <li><a href="http://projects.apache.org" title="The Projects">Projects</a></li>
+          <li><a href="http://people.apache.org" title="The People">People</a></li>
+          <li><a href="http://www.apache.org/foundation/getinvolved.html" title="Get Involved">Get Involved</a></li>
+          <li><a href="http://www.apache.org/dyn/closer.cgi" title="Download">Download</a></li>
+          <li><a href="http://www.apache.org/foundation/sponsorship.html" title="Support Apache">Support Apache</a></li>
+        </ul>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/wiki/">Wiki</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/">Core</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/">User-guide</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/">Jsf-and-myfaces-howtos</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/backend/">Backend</a></p>
+        <form name="search" id="search" action="http://www.google.com/search" method="get">
+          <input value="*.apache.org" name="sitesearch" type="hidden"/>
+          <input type="text" name="q" id="query">
+          <input type="submit" id="submit" value="Search">
+        </form>
+      </div>
+      <div class="clear"></div>
+      <div id="content" class="grid_16"><div class="section-content"><p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro>
+<ac:macro ac:name="info"><ac:rich-text-body>
+<p>In JSF 2.0 or later it is better to create a custom ResourceHandler
+wrapper and use FacesServlet instead. In that way, JSF will create
+FacesContext instance.</p></ac:rich-text-body></ac:macro></p>
+<h3>Nested FacesContext</h3>
+
+<p>If you create a custom FacesContext e.g. like described here
+<ac:link><ri:page ri:content-title="Access FacesContext From Servlet"
+/></ac:link> you might face a problem that e.g. messages added to your
+custom FacesContext won't show up in h:messages.</p>
+
+<p>The FacesServlet creates its own new FacesContext which will be used for
+all subsequent JSF operations.</p>
+
+<p>One reason why this is good is, that the FacesServlet can't be sure that
+your custom FacesContext use the correct ServletRequest/ServletResponse
+objects.</p>
+
+<p>An example when your custom FacesContext is not good is when you use
+requestDispatcher.forward.<br />
+Like my setup:</p>
+
+<ul>
+    <li>A custom filter which creates a custom FacesContext</li>
+    <li>A custom servlet which forwards to the FacesServlet
+(getServletContext().getRequestDispatcher(jsfPath).forward(req,
+res)<ac:emoticon ac:name="wink" /></li>
+    <li>The FacesServlet which creates a FacesContext too</li>
+</ul>
+
+<p>If the FacesServlet uses our own custom FacesContext you will see that
+JSF did not use the jsfPath for further operations, but the original url -
+which is false.</p>
+
+<p>So, I found to let the FacesServlet create a new FacesContext is fine
+and the easiest solution, but I still wanted it to show any messages added
+to the custom FacesContext.</p>
+
+<p>I ended with the following FacesContextFactory (adjust the package names
+as needed):</p>
+
+<p>Configuration in faces-config.xml:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    <factory></p>
+<p><faces-context-factory>org.apache....StateCopyFacesContextFactory</faces-context-factory>
+    </factory>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>Source:</p>
+
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">StateCopyFacesContextFactory.java</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+/<em>
+ * 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
+ </em>
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ <em>
+ * 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.
+</em>/
+package org.apache.....;</p>
+<p>import javax.faces.context.FacesContextFactory;
+import javax.faces.context.FacesContext;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
+import java.util.Iterator;</p>
+<p>/*<em>
+ * FacesContextFactory which first checks if a FacesContext is already
+there
+ </em>/
+public class StateCopyFacesContextFactory extends FacesContextFactory
+{
+    private final FacesContextFactory original;</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">StateCopyFacesContextFactory</span><span class="p">(</span><span class="n">FacesContextFactory</span> <span class="n">original</span><span class="p">)</span>
+<span class="p">{</span>
+    <span class="n">this</span><span class="p">.</span><span class="n">original</span> <span class="p">=</span> <span class="n">original</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="p">@</span><span class="n">Override</span>
+<span class="n">public</span> <span class="n">FacesContext</span> <span class="n">getFacesContext</span><span class="p">(</span><span class="n">Object</span> <span class="n">context</span><span class="p">,</span> <span class="n">Object</span> <span class="n">request</span><span class="p">,</span>
+</pre></div>
+
+
+<p>Object response, Lifecycle lifecycle) throws FacesException
+    {
+        FacesContext previousContext =
+FacesContext.getCurrentInstance();</p>
+<div class="codehilite"><pre>    <span class="n">FacesContext</span> <span class="n">newContext</span> <span class="p">=</span> <span class="n">original</span><span class="p">.</span><span class="n">getFacesContext</span><span class="p">(</span><span class="n">context</span><span class="p">,</span>
+</pre></div>
+
+
+<p>request, response, lifecycle);</p>
+<div class="codehilite"><pre>    <span class="k">if</span> <span class="p">(</span><span class="n">previousContext</span> !<span class="p">=</span> <span class="n">null</span><span class="p">)</span>
+    <span class="p">{</span>
+        <span class="o">//</span> <span class="n">transfer</span> <span class="n">the</span> <span class="n">default</span> <span class="n">locale</span> <span class="p">(</span><span class="n">might</span> <span class="n">have</span> <span class="n">been</span>
+</pre></div>
+
+
+<p>changed)</p>
+<p>newContext.getApplication().setDefaultLocale(previousContext.getApplication().getDefaultLocale());</p>
+<div class="codehilite"><pre>        <span class="o">//</span> <span class="n">transfer</span> <span class="n">all</span> <span class="n">already</span> <span class="n">collected</span> <span class="n">messages</span>
+        <span class="n">Iterator</span> <span class="n">iterClientIds</span> <span class="p">=</span>
+</pre></div>
+
+
+<p>previousContext.getClientIdsWithMessages();
+            while (iterClientIds.hasNext())
+            {
+                String clientId = (String)
+iterClientIds.next();
+                Iterator iterMessages =
+previousContext.getMessages(clientId);
+                while (iterMessages.hasNext())
+                {
+                    FacesMessage message =
+(FacesMessage) iterMessages.next();</p>
+<div class="codehilite"><pre>                <span class="n">newContext</span><span class="p">.</span><span class="n">addMessage</span><span class="p">(</span><span class="n">clientId</span><span class="p">,</span>
+</pre></div>
+
+
+<p>message);
+                }
+            }
+        }</p>
+<div class="codehilite"><pre>    <span class="k">return</span> <span class="n">newContext</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>Notice: This solution do not deal with resetting to the previousContext
+on newContext.release(). One can enhance it. For me it was sufficient that
+way as after the JSF request there is nothing further I will do with the
+FacesContext ... and the problem might be, that then one might copy some
+state back ... too complicated.</p>
+
+<p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro></p></div></div>
+      <div class="clear"></div>
+    </div>
+
+    <div id="copyright" class="container_16">
+      <p>Copyright &#169; 2011 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.</p>
+    </div>
+  </body>
+</html>

Added: websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/composite-components.html
==============================================================================
--- websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/composite-components.html (added)
+++ websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/composite-components.html Tue Jan 28 01:49:20 2014
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>Composite Components</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+
+    
+
+    
+    
+  </head>
+
+  <body>
+    <div id="page" class="container_16">
+      <div id="header" class="grid_8">
+        <img src="http://www.apache.org/images/feather-small.gif" alt="The Apache Software Foundation">
+        <h1>The Apache Software Foundation</h1>
+        <h2>Composite Components</h2>
+      </div>
+      <div id="nav" class="grid_8">
+        <ul>
+          <!-- <li><a href="/" title="Welcome!">Home</a></li> -->
+          <li><a href="http://www.apache.org/foundation/" title="The Foundation">Foundation</a></li>
+          <li><a href="http://projects.apache.org" title="The Projects">Projects</a></li>
+          <li><a href="http://people.apache.org" title="The People">People</a></li>
+          <li><a href="http://www.apache.org/foundation/getinvolved.html" title="Get Involved">Get Involved</a></li>
+          <li><a href="http://www.apache.org/dyn/closer.cgi" title="Download">Download</a></li>
+          <li><a href="http://www.apache.org/foundation/sponsorship.html" title="Support Apache">Support Apache</a></li>
+        </ul>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/wiki/">Wiki</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/">Core</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/">User-guide</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/">Jsf-and-myfaces-howtos</a></p>
+        <form name="search" id="search" action="http://www.google.com/search" method="get">
+          <input value="*.apache.org" name="sitesearch" type="hidden"/>
+          <input type="text" name="q" id="query">
+          <input type="submit" id="submit" value="Search">
+        </form>
+      </div>
+      <div class="clear"></div>
+      <div id="content" class="grid_16"><div class="section-content"><p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p><ac:macro ac:name="children"><ac:parameter
+ac:name="all">true</ac:parameter></ac:macro></p>
+<p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro></p></div></div>
+      <div class="clear"></div>
+    </div>
+
+    <div id="copyright" class="container_16">
+      <p>Copyright &#169; 2011 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.</p>
+    </div>
+  </body>
+</html>

Added: websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/composite-components/create-a-non-namingcontainer-composite-component.html
==============================================================================
--- websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/composite-components/create-a-non-namingcontainer-composite-component.html (added)
+++ websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/composite-components/create-a-non-namingcontainer-composite-component.html Tue Jan 28 01:49:20 2014
@@ -0,0 +1,206 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>Create a non NamingContainer Composite Component</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+
+    
+
+    
+    
+  </head>
+
+  <body>
+    <div id="page" class="container_16">
+      <div id="header" class="grid_8">
+        <img src="http://www.apache.org/images/feather-small.gif" alt="The Apache Software Foundation">
+        <h1>The Apache Software Foundation</h1>
+        <h2>Create a non NamingContainer Composite Component</h2>
+      </div>
+      <div id="nav" class="grid_8">
+        <ul>
+          <!-- <li><a href="/" title="Welcome!">Home</a></li> -->
+          <li><a href="http://www.apache.org/foundation/" title="The Foundation">Foundation</a></li>
+          <li><a href="http://projects.apache.org" title="The Projects">Projects</a></li>
+          <li><a href="http://people.apache.org" title="The People">People</a></li>
+          <li><a href="http://www.apache.org/foundation/getinvolved.html" title="Get Involved">Get Involved</a></li>
+          <li><a href="http://www.apache.org/dyn/closer.cgi" title="Download">Download</a></li>
+          <li><a href="http://www.apache.org/foundation/sponsorship.html" title="Support Apache">Support Apache</a></li>
+        </ul>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/wiki/">Wiki</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/">Core</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/">User-guide</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/">Jsf-and-myfaces-howtos</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/composite-components/">Composite-components</a></p>
+        <form name="search" id="search" action="http://www.google.com/search" method="get">
+          <input value="*.apache.org" name="sitesearch" type="hidden"/>
+          <input type="text" name="q" id="query">
+          <input type="submit" id="submit" value="Search">
+        </form>
+      </div>
+      <div class="clear"></div>
+      <div id="content" class="grid_16"><div class="section-content"><p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>In theory, a &quot;non explicit&quot; requeriment for a composite
+component class is it should implement NamingContainer interface. Note I
+said &quot;non explicit&quot;, because in practice there is nothing on JSF
+2.0 spec that enforces that.</p>
+
+<p>Let's take a look at this simple example:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+<h:form id="frmTst">
+       <ui:include src="demoui1.xhtml"/>
+       <ui:include src="demoui1.xhtml"/>
+       <ui:include src="demoui1.xhtml"/>
+</h:form>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">demoui1.xhtml</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+<ui:composition>
+   <p><h:commandButton value="Hello World!"/></p>
+</ui:composition>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>The previous code works in both MyFaces and Mojarra. This is valid from
+facelets 1.1.x. The idea is as long as there is no component with
+&quot;id&quot; set, the previous code will work. Combinations of c:if and
+ui:include could be possible, but this work well only on MyFaces 2.0.x and
+upper and facelets 1.1.x. In Mojarra 2.0.x some changes were done that
+makes such cases not work correctly (but in my opinion c:if is something
+evil, because it causes a lot of nightmares).</p>
+
+<p>Now let's try to convert the previous case into a composite component,
+but this time let's create a normal component that does not implement
+NamingContainer, because after all the previous snippet followed the rule
+that no components with id set were added:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+<h:form id="frmTst">
+       <test:ccc value="Hello World!"></test:ccc>
+       <test:ccc value="Hello World!"></test:ccc>
+       <test:ccc value="Hello World!"></test:ccc>
+</h:form>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">ccc.xhtml</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+<cc:interface componentType="test.ComponentCCC">
+       <cc:attribute name="value" type="java.lang.String" />
+</cc:interface>
+<cc:implementation>
+   <p><h:commandButton value="#{cc.attrs.value}"/></p>
+</cc:implementation>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">ComponentCCC.java</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+@FacesComponent("test.ComponentCCC")
+public class ComponentCCC extends UIOutput
+{
+   public final static String COMPONENT_TYPE = "test.ComponentCCC";</p>
+<p>@Override
+   public String getFamily()
+   {
+       return UINamingContainer.COMPONENT_FAMILY;
+   }
+}
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>In theory, since all ids are generated, everything should work like in
+ui:include case. In practice, the previous code works on MyFaces but does
+not on Mojarra.</p>
+
+<p>Why somebody could want to do this trick? Because NamingContainer has
+its effects, specially with UIComponent.findComponent. Suppose you want to
+create a component that works as a panel. You can imagine something like
+this:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+<h:form prependId="true">
+   <y:myPanel>
+       <h:inputText id="field1" ... />
+       <!-- more components -->
+   </y:myPanel>
+</h:form></p>
+<div class="codehilite"><pre><span class="p">{</span><span class="n">code</span><span class="p">:</span><span class="n">title</span><span class="p">=</span><span class="n">y</span><span class="p">.</span><span class="n">xhtml</span><span class="p">}</span>
+<span class="o">&lt;</span><span class="n">cc</span><span class="p">:</span><span class="n">implementation</span><span class="o">&gt;</span>
+   <span class="o">&lt;</span>!<span class="o">--</span> <span class="n">some</span> <span class="n">javascript</span> <span class="n">markup</span> <span class="n">with</span> <span class="n">html</span> <span class="n">and</span> <span class="n">css</span> <span class="o">--&gt;</span>
+   <span class="o">&lt;</span><span class="n">cc</span><span class="p">:</span><span class="n">insertChildren</span> <span class="o">/&gt;</span>
+   <span class="o">&lt;</span>!<span class="o">--</span> <span class="n">some</span> <span class="n">javascript</span> <span class="n">markup</span> <span class="n">with</span> <span class="n">html</span> <span class="n">and</span> <span class="n">css</span> <span class="o">--&gt;</span>
+<span class="o">&lt;</span><span class="n">cc</span><span class="p">:</span><span class="n">implementation</span><span class="o">&gt;</span>
+<span class="p">]</span>
+</pre></div>
+
+
+<p>]&gt;</ac:plain-text-body></ac:macro></p>
+<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">p</span><span class="o">&gt;</span><span class="n">The</span> <span class="n">user</span> <span class="n">wants</span> <span class="n">that</span> <span class="n">the</span> <span class="n">final</span> <span class="n">clientId</span> <span class="n">be</span> <span class="o">&amp;</span><span class="n">quot</span><span class="p">;</span><span class="n">field1</span><span class="o">&amp;</span><span class="n">quot</span><span class="p">;,</span> <span class="n">but</span>
+</pre></div>
+
+
+<p>instead he/she has &quot;<ac:link><ri:page ri:content-title="generated id"
+/></ac:link>:field1&quot;, and the worst part is if you need some call to
+invokeOnComponent or findComponent, you have to set the id of your
+composite component and take into account the internals of such cc to get
+the component instance.</p></p>
+<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">p</span><span class="o">&gt;</span><span class="n">There</span> <span class="n">is</span> <span class="n">an</span> <span class="n">easy</span> <span class="n">solution</span> <span class="n">that</span> <span class="n">works</span> <span class="n">with</span> <span class="n">both</span> <span class="n">MyFaces</span> <span class="n">and</span> <span class="n">Mojarra</span><span class="p">.</span> <span class="n">The</span>
+</pre></div>
+
+
+<p>idea is just wrap everything inside cc:implementation with f:subview, which
+creates a NamingContainer component:</p></p>
+<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">ac</span><span class="p">:</span><span class="n">macro</span>
+</pre></div>
+
+
+<p>ac:name="code"&gt;<ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    <cc:interface componentType="test.ComponentCCC">
+           <cc:attribute name="value" type="java.lang.String" />
+    </cc:interface>
+    <cc:implementation>
+    <f:subview id="#{cc.id}_p">
+       <p><h:commandButton value="#{cc.attrs.value}"/></p>
+       <!-- more markup here -->
+    </f:subview>
+    </cc:implementation>
+    ]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">p</span><span class="o">&gt;</span><span class="n">Works</span> <span class="n">great</span><span class="p">,</span> <span class="n">because</span> <span class="n">the</span> <span class="n">internal</span> <span class="n">markup</span> <span class="n">uses</span> <span class="n">the</span> <span class="n">naming</span> <span class="n">container</span><span class="p">,</span> <span class="n">but</span>
+</pre></div>
+
+
+<p>the composite component base is not a naming container, so its children or
+facets will not be affected. Obviously, if you use cc:insertChildren and
+cc:insertFacet the components will be relocated and affected by the
+NamingContainer.</p></p>
+<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">p</span><span class="o">&gt;</span><span class="n">Note</span> <span class="n">this</span> <span class="n">hack</span> <span class="n">becomes</span> <span class="n">useful</span> <span class="n">when</span> <span class="n">you</span> <span class="n">have</span> <span class="n">facelets</span> 1<span class="p">.</span>1<span class="p">.</span><span class="n">x</span> <span class="n">pages</span> <span class="n">and</span> <span class="n">you</span>
+</pre></div>
+
+
+<p>want to convert them to composite components, so if you are creating new
+composite components it is better to keep them as NamingContainer
+instances, unless by some reason (like in the panel problem) you need the
+root component not to be a NamingContainer.</p></p>
+<div class="codehilite"><pre><span class="o">&lt;</span><span class="n">ac</span><span class="p">:</span><span class="n">macro</span> <span class="n">ac</span><span class="p">:</span><span class="n">name</span><span class="p">=</span>&quot;<span class="n">info</span>&quot;<span class="o">&gt;&lt;</span><span class="n">ac</span><span class="p">:</span><span class="n">rich</span><span class="o">-</span><span class="n">text</span><span class="o">-</span><span class="n">body</span><span class="o">&gt;&lt;</span><span class="n">p</span><span class="o">&gt;</span><span class="n">See</span> <span class="p">[</span><span class="n">jsr</span><span class="o">-</span>344<span class="o">-</span><span class="n">experts</span><span class="p">]</span>
+</pre></div>
+
+
+<p><a
+href="http://java.net/projects/javaserverfaces-spec-public/lists/jsr344-experts/archive/2011-07/message/2">should
+really a composite component requires NamingContainer interface?</a> for
+more information.</p></ac:rich-text-body></ac:macro>
+    <ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA[{scrollbar}]
+]&gt;</ac:plain-text-body></ac:macro></p></div></div>
+      <div class="clear"></div>
+    </div>
+
+    <div id="copyright" class="container_16">
+      <p>Copyright &#169; 2011 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.</p>
+    </div>
+  </body>
+</html>

Added: websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings.html
==============================================================================
--- websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings.html (added)
+++ websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings.html Tue Jan 28 01:49:20 2014
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>Managing Errors - Infos - Warnings</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+
+    
+
+    
+    
+  </head>
+
+  <body>
+    <div id="page" class="container_16">
+      <div id="header" class="grid_8">
+        <img src="http://www.apache.org/images/feather-small.gif" alt="The Apache Software Foundation">
+        <h1>The Apache Software Foundation</h1>
+        <h2>Managing Errors - Infos - Warnings</h2>
+      </div>
+      <div id="nav" class="grid_8">
+        <ul>
+          <!-- <li><a href="/" title="Welcome!">Home</a></li> -->
+          <li><a href="http://www.apache.org/foundation/" title="The Foundation">Foundation</a></li>
+          <li><a href="http://projects.apache.org" title="The Projects">Projects</a></li>
+          <li><a href="http://people.apache.org" title="The People">People</a></li>
+          <li><a href="http://www.apache.org/foundation/getinvolved.html" title="Get Involved">Get Involved</a></li>
+          <li><a href="http://www.apache.org/dyn/closer.cgi" title="Download">Download</a></li>
+          <li><a href="http://www.apache.org/foundation/sponsorship.html" title="Support Apache">Support Apache</a></li>
+        </ul>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/wiki/">Wiki</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/">Core</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/">User-guide</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/">Jsf-and-myfaces-howtos</a></p>
+        <form name="search" id="search" action="http://www.google.com/search" method="get">
+          <input value="*.apache.org" name="sitesearch" type="hidden"/>
+          <input type="text" name="q" id="query">
+          <input type="submit" id="submit" value="Search">
+        </form>
+      </div>
+      <div class="clear"></div>
+      <div id="content" class="grid_16"><div class="section-content"><p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p><ac:macro ac:name="children"><ac:parameter
+ac:name="all">true</ac:parameter></ac:macro></p>
+<p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro></p></div></div>
+      <div class="clear"></div>
+    </div>
+
+    <div id="copyright" class="container_16">
+      <p>Copyright &#169; 2011 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.</p>
+    </div>
+  </body>
+</html>

Added: websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings/displaying-errors---infos---warnings-in-jsf-pages.html
==============================================================================
--- websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings/displaying-errors---infos---warnings-in-jsf-pages.html (added)
+++ websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings/displaying-errors---infos---warnings-in-jsf-pages.html Tue Jan 28 01:49:20 2014
@@ -0,0 +1,326 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>Displaying Errors - Infos - Warnings in JSF pages</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+
+    
+
+    
+    
+  </head>
+
+  <body>
+    <div id="page" class="container_16">
+      <div id="header" class="grid_8">
+        <img src="http://www.apache.org/images/feather-small.gif" alt="The Apache Software Foundation">
+        <h1>The Apache Software Foundation</h1>
+        <h2>Displaying Errors - Infos - Warnings in JSF pages</h2>
+      </div>
+      <div id="nav" class="grid_8">
+        <ul>
+          <!-- <li><a href="/" title="Welcome!">Home</a></li> -->
+          <li><a href="http://www.apache.org/foundation/" title="The Foundation">Foundation</a></li>
+          <li><a href="http://projects.apache.org" title="The Projects">Projects</a></li>
+          <li><a href="http://people.apache.org" title="The People">People</a></li>
+          <li><a href="http://www.apache.org/foundation/getinvolved.html" title="Get Involved">Get Involved</a></li>
+          <li><a href="http://www.apache.org/dyn/closer.cgi" title="Download">Download</a></li>
+          <li><a href="http://www.apache.org/foundation/sponsorship.html" title="Support Apache">Support Apache</a></li>
+        </ul>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/wiki/">Wiki</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/">Core</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/">User-guide</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/">Jsf-and-myfaces-howtos</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings/">Managing-errors---infos---warnings</a></p>
+        <form name="search" id="search" action="http://www.google.com/search" method="get">
+          <input value="*.apache.org" name="sitesearch" type="hidden"/>
+          <input type="text" name="q" id="query">
+          <input type="submit" id="submit" value="Search">
+        </form>
+      </div>
+      <div class="clear"></div>
+      <div id="content" class="grid_16"><div class="section-content"><p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro>
+<p>One common question about JSF is how to manage messages of various
+types, which are generated by JSF components and backing beans. This
+discussion is designed as an introduction to the topic and focused on entry
+to mid-level JSF users.</p></p>
+<p>The pattern described here is just one approach that we developed which
+meets our needs for:</p>
+
+<ol>
+    <li>Providing a consistent and generic means for including
+processing messages in all JSF pages.</li>
+    <li>Decorating the messages with images and styles to differentiate
+severity levels to the user which is browser safe.</li>
+    <li>Add additional messages when appropriate.</li>
+    <li>Be localizable.</li>
+    <li>Not affect page layouts when no errors are generated.</li>
+</ol>
+
+<h3>Discussion</h3>
+
+<p>Our user-interface requirements dictate that (a) as far as the user is
+concerned there is no such thing as an error, (b) the system should provide
+as little information as necessary to draw the user's attention to any
+issues raised during processing and help them correct the problem, (c)
+inform on all operations which change state in the back-end (success as
+well as failure), and (d) provide a way out (i.e. graceful means for
+backing out of any failed operation).</p>
+
+<p>While (a) and (d) require detailed discussion on overall system design
+which is out of scope of this topic, (b) and (c) are certainly within the
+purview of this JSF discussion and are our points of focus.</p>
+
+<h3>JSF message components</h3>
+
+<p>The basic mechanism for managing page-specific messages is to include
+<code>&lt;h:message&gt;</code> and <code>&lt;h:messages&gt;</code> tags in
+the JSF page. &lt;h:message&gt; is component specific (i.e. tied to a
+particular JSF component ID) while &lt;h:messages&gt; can provide global
+messaging as well as roll-up all component specific messages. Our
+experience is that <code>&lt;h:message&gt;</code> is useful for components
+which have validation but the <code>&lt;h:messages&gt;</code> tag needs to
+be better managed to control layout and information-provision. For example,
+rather than displaying a list of validation errors that have been generated
+we would like to provide a new message such as 'One or more fields have
+missing or invalid values. Please re-check the fields indicated below and
+re-submit the form.'</p>
+
+<p>JSF message tags display messages which have been queued as the request
+is processed. Each message that is queued has a message priority which is
+one of the FacesMessage priorities defined in
+javax.faces.application.FacesMessage and are defined as</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>java</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    public static final FacesMessage.Severity SEVERITY_INFO = new
+Severity("Info", 1);
+    public static final FacesMessage.Severity SEVERITY_WARN = new
+Severity("Warn", 2);
+    public static final FacesMessage.Severity SEVERITY_ERROR = new
+Severity("Error", 3);
+    public static final FacesMessage.Severity SEVERITY_FATAL = new
+Severity("Fatal", 4);
+]
+]&gt;</ac:plain-text-body></ac:macro>
+<p>and can be either associated with a component or not. When a message is
+generated during processing, the component, validator or backing generating
+the message palces the message into one of the message queues where it can
+be accessed by the JSF during the rendering phase.</p></p>
+<h3>Generating Messages</h3>
+
+<p>Messages (error/info/warn/fatal) can be enqueued by calling the
+FacesContext.getCurrentInstance().addMessage() method. Our requirements
+state that messages are displayed on all change in state as well as
+processing errors such as bad databases retrievals etc. which means that
+the majority of our pages need to be able to generate messages. To this
+end, we found it is convienient to put quick-access methods in a base class
+and sub-class all backing beans from it. This is similar to how Sun
+Creator's 1.0 manages backing beans and our methods are adopted from this.
+For severity our base class has two methods as below for INFO.</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>java</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+   protected void setInfoMessage(String summary) {</p>
+<div class="codehilite"><pre><span class="n">getFacesContext</span><span class="p">().</span><span class="n">addMessage</span><span class="p">(</span><span class="n">null</span><span class="p">,</span> <span class="n">new</span>
+</pre></div>
+
+
+<p>FacesMessage(FacesMessage.SEVERITY_INFO, summary, null));</p>
+<div class="codehilite"><pre><span class="p">}</span>
+
+
+
+<span class="n">protected</span> <span class="n">void</span> <span class="n">setInfoMessage</span><span class="p">(</span><span class="n">UIComponent</span> <span class="n">component</span><span class="p">,</span> <span class="n">String</span> <span class="n">summary</span><span class="p">)</span> <span class="p">{</span>
+</pre></div>
+
+
+<p>getFacesContext().addMessage(component.getClientId(getFacesContext()), new
+FacesMessage(FacesMessage.SEVERITY_INFO, summary, null));</p>
+<div class="codehilite"><pre><span class="p">}</span>
+</pre></div>
+
+
+<p>]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>The first method enqueues a global message with INFO severity while the
+second method associates the INFO message with a component (most probably
+from a custom (page-specific) validation. We also have a base class for all
+our validators (which perform page-specific validation when necessary)
+which uses the following protected method for raising messages</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>java</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    protected static void invalidateInput(UIInput uii, String message) {</p>
+<div class="codehilite"><pre><span class="n">uii</span><span class="p">.</span><span class="n">setValid</span><span class="p">(</span><span class="n">false</span><span class="p">);</span>
+
+<span class="n">FacesMessage</span> <span class="n">facesMessage</span> <span class="p">=</span> <span class="n">new</span>
+</pre></div>
+
+
+<p>FacesMessage(FacesMessage.SEVERITY_WARN, message, null);</p>
+<div class="codehilite"><pre><span class="n">throw</span> <span class="n">new</span> <span class="n">ValidatorException</span><span class="p">(</span><span class="n">facesMessage</span><span class="p">);</span>
+
+<span class="p">}</span>
+</pre></div>
+
+
+<p>]
+]&gt;</ac:plain-text-body></ac:macro>
+<p>Note that we only raise messages with WARN severity as our requirements
+preclude displaying anything which looks or smells like an error to our
+users.  </p></p>
+<p>As all our backing beans have these methods accesible to them, we can
+simply add appropriate calls to enqueue messages in our business logic such
+as</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>java</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+        setInfoMessage(Messages.getString("MANIFEST_SAVED"));</p>
+<p>or</p>
+<div class="codehilite"><pre>    <span class="n">setWarnMessage</span><span class="p">(</span><span class="n">Messages</span><span class="p">.</span><span class="n">getString</span><span class="p">(</span>&quot;<span class="n">UPDATE_DATABASE_ERROR</span>&quot;<span class="p">));</span>
+</pre></div>
+
+
+<p>or</p>
+<div class="codehilite"><pre>    <span class="n">setInfoMessage</span><span class="p">(</span><span class="n">Messages</span><span class="p">.</span><span class="n">getString</span><span class="p">(</span>&quot;<span class="n">STORAGE_TRANSFER_ONE</span>&quot;<span class="p">,</span> <span class="n">new</span>
+</pre></div>
+
+
+<p>Integer(count), fromUnit.getName(), toUnit.getName()));
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>where the Messages class provides access to a messages properties file
+and performs standard parameter replacement using Apache's Common Lang
+StringUtils.</p>
+
+<h3>Displaying Messages</h3>
+
+<p>Rasing messages is one topic, displaying them another. As we need a
+consistent look and feel for all messages we choose to include a JSP in
+each page which handles all messages which are not component specific. Our
+PageMessages.jspf is as follows:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+&lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%&gt;
+&lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%&gt;
+&lt;%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%&gt;</p>
+<p><h:panelGrid styleClass="group" columns="2" cellpadding="2" cellspacing="0"
+width="100%" columnClasses="buttonCol, leftAlignCol"
+rowClasses="vertAlignTop" rendered="#{! empty
+facesContext.maximumSeverity}" >
+    <h:graphicImage value="#{PageMessages.messageImage}" style="float:
+left; vertical-align: top;" />     <br />
+    <h:panelGrid columns="1" cellpadding="2" cellspacing="2"
+columnClasses="leftAlignCol" rowClasses="vertAlignTop" width="100%"> <br />
+        <h:outputText value="#{PageMessages.messageHeader}"
+escape="false" rendered="#{PageMessages.renderMessage}"/>
+        <h:messages errorClass="errorMessage" infoClass="infoMessage"
+layout="table" globalOnly="true" showDetail="false" showSummary="true"/>
+    </h:panelGrid>
+</h:panelGrid>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>The messages are only displayed only if one or more messages are
+enqueued by conditionally rendering the table using
+<code>rendered=&quot;#{! empty facesContext.maximumSeverity}&quot;</code>
+which uses EL to check if the queues are empty or not. Depending on the
+level of severity we display an themed image followed by an optional
+pre-amble to the messages and then the global messages themselves. The
+global messages are displayed in table format.</p>
+
+<p>You will notice that we use a backing bean (PageMessages.java) in <span
+style="text-decoration: underline;">request scope</span> to control the
+JSPF. The code for this is as follows:</p>
+
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">PageMessages.java</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+import Messages;</p>
+<p>import org.apache.commons.lang.StringUtils;</p>
+<p>import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;</p>
+<p>public class PageMessages extends AbstractUIBean {
+    private static final long serialVersionUID = -6479897299239746841L;
+    private static final String BEAN_NAME = PageMessages.class.getName();
+    private String messageHeader;
+    private String messageImage;
+    private Severity severityLevel;</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">PageMessages</span><span class="p">()</span> <span class="p">{</span>
+<span class="n">messageHeader</span> <span class="p">=</span> <span class="n">null</span><span class="p">;</span>
+
+<span class="o">//</span> <span class="n">See</span> <span class="k">if</span> <span class="n">there</span> <span class="n">are</span> <span class="n">messages</span> <span class="n">queued</span> <span class="k">for</span> <span class="n">the</span> <span class="n">page</span>
+<span class="n">severityLevel</span> <span class="p">=</span> <span class="n">getFacesContext</span><span class="p">().</span><span class="n">getMaximumSeverity</span><span class="p">();</span>
+
+<span class="k">if</span> <span class="p">(</span><span class="n">null</span> !<span class="p">=</span> <span class="n">severityLevel</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">getLogger</span><span class="p">().</span><span class="n">debug</span><span class="p">(</span>&quot;<span class="n">Severity</span> <span class="n">Level</span> <span class="n">Trapped</span><span class="p">:</span> <span class="n">level</span> <span class="p">=</span> <span class="s">&#39;</span><span class="err">&quot; +</span>
+</pre></div>
+
+
+<p>severityLevel.toString() + "'");</p>
+<div class="codehilite"><pre>    <span class="k">if</span> <span class="p">(</span><span class="n">severityLevel</span><span class="p">.</span><span class="n">equals</span><span class="p">(</span><span class="n">FacesMessage</span><span class="p">.</span><span class="n">SEVERITY_ERROR</span><span class="p">))</span> <span class="p">{</span>
+    <span class="n">messageHeader</span> <span class="p">=</span> <span class="n">Messages</span><span class="p">.</span><span class="n">getString</span><span class="p">(</span>&quot;<span class="n">PAGE_MESSAGE_ERROR</span>&quot;<span class="p">);</span>
+    <span class="n">messageImage</span> <span class="p">=</span> &quot;<span class="n">resources</span><span class="o">/</span><span class="n">warning</span><span class="p">.</span><span class="n">gif</span>&quot;<span class="p">;</span>
+    <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">severityLevel</span><span class="p">.</span><span class="n">equals</span><span class="p">(</span><span class="n">FacesMessage</span><span class="p">.</span><span class="n">SEVERITY_INFO</span><span class="p">))</span> <span class="p">{</span>
+    <span class="n">messageHeader</span> <span class="p">=</span> <span class="n">null</span><span class="p">;</span>
+    <span class="n">messageImage</span> <span class="p">=</span> &quot;<span class="n">resources</span><span class="o">/</span><span class="n">information</span><span class="p">.</span><span class="n">gif</span>&quot;<span class="p">;</span>
+    <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">severityLevel</span><span class="p">.</span><span class="n">equals</span><span class="p">(</span><span class="n">FacesMessage</span><span class="p">.</span><span class="n">SEVERITY_WARN</span><span class="p">))</span> <span class="p">{</span>
+    <span class="n">messageHeader</span> <span class="p">=</span> <span class="n">null</span><span class="p">;</span>
+    <span class="n">messageImage</span> <span class="p">=</span> &quot;<span class="n">resources</span><span class="o">/</span><span class="n">warning</span><span class="p">.</span><span class="n">gif</span>&quot;<span class="p">;</span>
+    <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">severityLevel</span><span class="p">.</span><span class="n">equals</span><span class="p">(</span><span class="n">FacesMessage</span><span class="p">.</span><span class="n">SEVERITY_FATAL</span><span class="p">))</span> <span class="p">{</span>
+    <span class="n">messageHeader</span> <span class="p">=</span> <span class="n">Messages</span><span class="p">.</span><span class="n">getString</span><span class="p">(</span>&quot;<span class="n">PAGE_FATAL_ERROR</span>&quot;<span class="p">);</span>
+    <span class="n">messageImage</span> <span class="p">=</span> &quot;<span class="n">resources</span><span class="o">/</span><span class="n">stop</span><span class="p">.</span><span class="n">gif</span>&quot;<span class="p">;</span>
+    <span class="p">}</span>
+<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+    <span class="n">getLogger</span><span class="p">().</span><span class="n">debug</span><span class="p">(</span>&quot;<span class="n">Severity</span> <span class="n">Level</span> <span class="n">Trapped</span><span class="p">:</span> <span class="n">level</span> <span class="p">=</span> <span class="s">&#39;null&#39;</span>&quot;<span class="p">);</span>
+<span class="p">}</span>
+<span class="p">}</span>
+
+<span class="n">public</span> <span class="n">Boolean</span> <span class="n">getRenderMessage</span><span class="p">()</span> <span class="p">{</span>
+<span class="k">return</span> <span class="n">new</span> <span class="n">Boolean</span><span class="p">(</span><span class="n">StringUtils</span><span class="p">.</span><span class="n">isNotBlank</span><span class="p">(</span><span class="n">getMessageHeader</span><span class="p">()));</span>
+<span class="p">}</span>
+
+<span class="n">public</span> <span class="n">String</span> <span class="n">getBeanName</span><span class="p">()</span> <span class="p">{</span>
+<span class="k">return</span> <span class="n">BEAN_NAME</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="n">public</span> <span class="n">String</span> <span class="n">getMessageHeader</span><span class="p">()</span> <span class="p">{</span>
+<span class="k">return</span> <span class="n">messageHeader</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="n">public</span> <span class="n">String</span> <span class="n">getMessageImage</span><span class="p">()</span> <span class="p">{</span>
+<span class="k">return</span> <span class="n">messageImage</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}
+]
+]&gt;</ac:plain-text-body></ac:macro>
+<p>Our backing bean extends our basic UI base classes which provides access
+to central logging etc. You can see that if a component has enqueued a
+message of ERROR we add a localized message at the top of the page which
+(we hope) gracefully moderates the user-impact of seeing the same form
+again with a bunch of annotations!</p></p>
+<p>The PageMessages.jspf is included into each JSP using the following
+code:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+<f:subview id="messages">
+    <jsp:directive.include file="PageMessages.jspf" />
+</f:subview>
+]
+]&gt;</ac:plain-text-body></ac:macro>
+<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro></p></div></div>
+      <div class="clear"></div>
+    </div>
+
+    <div id="copyright" class="container_16">
+      <p>Copyright &#169; 2011 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.</p>
+    </div>
+  </body>
+</html>

Added: websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings/handling-server-errors.html
==============================================================================
--- websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings/handling-server-errors.html (added)
+++ websites/staging/myfaces/trunk/content/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings/handling-server-errors.html Tue Jan 28 01:49:20 2014
@@ -0,0 +1,650 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="en">
+  <head>
+    <title>Handling Server Errors</title>
+
+    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
+    <meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
+
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
+    <link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/code.css">
+
+    
+
+    
+    
+  </head>
+
+  <body>
+    <div id="page" class="container_16">
+      <div id="header" class="grid_8">
+        <img src="http://www.apache.org/images/feather-small.gif" alt="The Apache Software Foundation">
+        <h1>The Apache Software Foundation</h1>
+        <h2>Handling Server Errors</h2>
+      </div>
+      <div id="nav" class="grid_8">
+        <ul>
+          <!-- <li><a href="/" title="Welcome!">Home</a></li> -->
+          <li><a href="http://www.apache.org/foundation/" title="The Foundation">Foundation</a></li>
+          <li><a href="http://projects.apache.org" title="The Projects">Projects</a></li>
+          <li><a href="http://people.apache.org" title="The People">People</a></li>
+          <li><a href="http://www.apache.org/foundation/getinvolved.html" title="Get Involved">Get Involved</a></li>
+          <li><a href="http://www.apache.org/dyn/closer.cgi" title="Download">Download</a></li>
+          <li><a href="http://www.apache.org/foundation/sponsorship.html" title="Support Apache">Support Apache</a></li>
+        </ul>
+        <p><a href="/">Home</a>&nbsp;&raquo&nbsp;<a href="/wiki/">Wiki</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/">Core</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/">User-guide</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/">Jsf-and-myfaces-howtos</a>&nbsp;&raquo&nbsp;<a href="/wiki/core/user-guide/jsf-and-myfaces-howtos/managing-errors---infos---warnings/">Managing-errors---infos---warnings</a></p>
+        <form name="search" id="search" action="http://www.google.com/search" method="get">
+          <input value="*.apache.org" name="sitesearch" type="hidden"/>
+          <input type="text" name="q" id="query">
+          <input type="submit" id="submit" value="Search">
+        </form>
+      </div>
+      <div class="clear"></div>
+      <div id="content" class="grid_16"><div class="section-content"><p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro>
+<h2>Error handling for MyFaces Core 2.0 and later versions</h2></p>
+<p>Since JSF 2.0, it is possible to provide a custom
+javax.faces.context.ExceptionHandler or
+javax.faces.context.ExceptionHandlerWrapper implementation to deal with
+exceptions. To do that, just create your custom class, an factory that
+wrap/override it and add the following into your faces-config.xml:</p>
+
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">faces-config.xml</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee" 
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" 
+          version="2.0"></p>
+<div class="codehilite"><pre><span class="o">&lt;</span>!<span class="o">--</span> <span class="p">...</span> <span class="o">--&gt;</span>
+<span class="o">&lt;</span><span class="n">factory</span><span class="o">&gt;</span>
+<span class="o">&lt;</span>!<span class="o">--</span> <span class="p">...</span> <span class="o">--&gt;</span>
+</pre></div>
+
+
+<p><exception-handler-factory>org.apache.myfaces.context.ExceptionHandlerFactoryImpl</exception-handler-factory>
+    <!-- ... -->
+    </factory>
+    <!-- ... -->
+</faces-config>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>This is an example of an ExceptionHandlerFactory, from myfaces code:</p>
+
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">ExceptionHandlerFactoryImpl.java</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+public class ExceptionHandlerFactoryImpl extends ExceptionHandlerFactory
+{</p>
+<div class="codehilite"><pre><span class="p">@</span><span class="n">Override</span>
+<span class="n">public</span> <span class="n">ExceptionHandler</span> <span class="n">getExceptionHandler</span><span class="p">()</span>
+<span class="p">{</span>
+<span class="k">return</span> <span class="n">new</span> <span class="n">SwitchAjaxExceptionHandlerWrapperImpl</span><span class="p">(</span>
+    <span class="n">new</span> <span class="n">MyFacesExceptionHandlerWrapperImpl</span><span class="p">(</span><span class="n">new</span>
+</pre></div>
+
+
+<p>ExceptionHandlerImpl()) , 
+        new AjaxExceptionHandlerImpl());
+    }
+}
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>If you need a wrapper:</p>
+
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">ExceptionHandlerFactoryImpl.java</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+public class ExceptionHandlerFactoryImpl extends ExceptionHandlerFactory
+{</p>
+<div class="codehilite"><pre><span class="p">@</span><span class="n">Override</span>
+<span class="n">public</span> <span class="n">ExceptionHandler</span> <span class="n">getExceptionHandler</span><span class="p">()</span>
+<span class="p">{</span>
+<span class="k">return</span> <span class="n">new</span>
+</pre></div>
+
+
+<p>CustomExceptionHandlerWrapper(getWrapped().getExceptionHandler());
+    }
+}
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>The most important method to override is
+<code>ExceptionHandler.handle()</code>. </p>
+
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">MyFacesExceptionHandlerWrapperImpl.java</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+public class MyFacesExceptionHandlerWrapperImpl extends
+ExceptionHandlerWrapper
+{
+    //...
+    public void handle() throws FacesException
+    {
+       //... some custom code goes here ...
+    }
+}
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>Take a look at MyFaces Core source code, to know in detail how
+ExceptionHandler implementations works.</p>
+
+<h3>MyFaces ExceptionHandler</h3>
+
+<p>MyFaces Core provide a custom ExceptionHandler to deal with exceptions
+and provide detailed information about it. Since 2.0.8/2.1.2 this is
+disabled on Production environments unless it enabled on web.xml file.
+Don't forget to provide your custom error page in this scenario, to prevent
+show more information than necessary.</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+  <context-param>
+    <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
+    <param-value>true</param-value>
+  </context-param></p>
+<p><!-- if you want to use a different resource template file than 
+       "META-INF/rsc/myfaces-dev-error.xml" this param let you configure
+       it. (since 1.2.4-SNAPSHOT and 1.1.6-SNAPSHOT)-->
+  <context-param>
+    <param-name>org.apache.myfaces.ERROR_TEMPLATE_RESOURCE</param-name>
+    <param-value>META-INF/rsc/custom-dev-error.xml</param-value>
+  </context-param>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<h3>Provide an error page</h3>
+
+<p>The default ExceptionHandler in Production stage or when myfaces error
+handling is disabled just throw an exception. So you can still setup an
+error page adding something like this in your web.xml file:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    <error-page>
+        <error-code>500</error-code>
+        <location>/somepage.jsp</location>
+    </error-page>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<h2>Error handling for MyFaces Core 1.2 and earlier versions</h2>
+
+<p>MyFaces, from version 1.2.1 and 1.1.6, includes automatic error-handling
+for the full JSF-Lifecycle (taken over mostly from Facelets, with a few
+adoptions and additions). So for most projects during development, you will
+have exactly what you want with these new error-handling possibilities.
+</p>
+
+<p>If this is not what you want, though, you can always disable or modify
+this error-handling with the following parameters:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+  <!-- if you want to disable the behaviour completely -->
+  <context-param>
+    <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
+    <param-value>false</param-value>
+  </context-param>
+  <!-- if you are using myfaces + facelets don't forget to do this -->
+  <context-param>
+    <param-name>facelets.DEVELOPMENT</param-name>
+    <param-value>false</param-value>
+  </context-param></p>
+<p><!-- if you want to use a different resource template file than 
+       "META-INF/rsc/myfaces-dev-error.xml" this param let you configure
+       it. (since 1.2.4-SNAPSHOT and 1.1.6-SNAPSHOT)-->
+  <context-param>
+    <param-name>org.apache.myfaces.ERROR_TEMPLATE_RESOURCE</param-name>
+    <param-value>META-INF/rsc/custom-dev-error.xml</param-value>
+  </context-param></p>
+<p><!-- if you want to choose a different class for handling the exception -
+the error-handler needs to include a method handleException(FacesContext
+fc, Exception ex)-->
+  <context-param>
+    <param-name>org.apache.myfaces.ERROR_HANDLER</param-name>
+    <param-value>my.project.ErrorHandler</param-value>
+  </context-param> 
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>If you do this, you can now read on to get to general ways of handling
+server-errors.</p>
+
+<p>Server errors such as HTTP 500 can occur for a number of reasons such as
+uncaught exceptions, missing JSFs or backing beans, bad URL and the list
+goes on. While we hope these only occur during development it is important
+to plan to catch and deal with these errors gracefully when running live
+with multiple users.</p>
+
+<p>Several approaches have been discussed on the mailing list:</p>
+
+<h3>Use default handler</h3>
+
+<p>Myfaces has a default error handler (class
+javax.faces.webapp._ErrorPageWriter) that uses a jsp template file
+(META-INF/rsc/myfaces-dev-error.xml and META-INF/rsc/myfaces-dev-debug.xml)
+to handle errors.</p>
+
+<p>For define a custom template file:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+  <context-param>
+    <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
+    <param-value>true</param-value>
+  </context-param></p>
+<p><context-param>
+    <param-name>org.apache.myfaces.ERROR_TEMPLATE_RESOURCE</param-name>
+    <param-value>META-INF/rsc/mycustom-template-error.xml</param-value>
+  </context-param>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<h3>Use sandbox
+org.apache.myfaces.tomahawk.util.ErrorRedirectJSFPageHandler</h3>
+
+<p>This handler uses myfaces error handling feature, redirecting to a jsf
+page when an error occurs.</p>
+
+<p>An example jsf page for redirect can be found at <a
+class="external-link"
+href="http://issues.apache.org/jira/browse/TOMAHAWK-1297"
+rel="nofollow">http://issues.apache.org/jira/browse/TOMAHAWK-1297</a></p>
+
+<p>This class is set as a config-parameter
+org.apache.myfaces.ERROR_HANDLER<br />
+available on myfaces core jsf. (This does not work with RI)</p>
+
+<p>The idea is extends myfaces error handling feature, making possible to
+redirect<br />
+to a jsf page when an error occur, using navigation rules.</p>
+
+<p>If this handler is not able to handle the error, an alternate error
+handler<br />
+could be set in the config-parameter
+org.apache.myfaces.ERROR_REDIRECT_ALTERNATE_HANDLER</p>
+
+<p>The info of the error in the jsf page can be found using:</p>
+
+<p><ac:macro ac:name="code"><ac:plain-text-body>&lt;![CDATA[
+1. {exceptionContext.cause} : Cause retrieved from the exception
+1. {exceptionContext.stackTrace} : Stack trace of the exception
+1. {exceptionContext.exception} : Exception handled by this page 
+1. {exceptionContext.tree} : Print the component tree of the page that cause
+the error
+1. {exceptionContext.vars} : Enviroment variables from the request
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<h3>Using servlets</h3>
+
+<p>Mert Caliskan (<a class="external-link"
+href="http://www.jroller.com/page/mert?entry=handling_errors_with_an_errror"
+rel="nofollow">http://www.jroller.com/page/mert?entry=handling_errors_with_an_errror</a>)
+describes an approach which wraps the JSF servlet with a new servlet which
+delegates to the faces servlet but handles uncaught exceptions allowing the
+developer to redirect to a custom error page.</p>
+
+<p>Andrea Paternesi has refined this technique for MyFaces as described
+here: <br />
+[<a href="http://patton-prog-tips.blogspot.com/2008/10/myfaces-handling-viewexpiredexception.html">http://patton-prog-tips.blogspot.com/2008/10/myfaces-handling-viewexpiredexception.html</a>](<a-href="http://patton-prog-tips.blogspot.com/2008/10/myfaces-handling-viewexpiredexception.html">http://patton-prog-tips.blogspot.com/2008/10/myfaces-handling-viewexpiredexception.html</a>.html)
+</p>
+
+<h3>With JSF</h3>
+
+<p>Another approach is described in the book 'Core Server Faces' which uses
+the servlet engine to catch the error and delegate to a JSF error page.
+While not as elegant as the  first approach this method has several
+advantages for some users</p>
+
+<p><ac:link><ri:page ri:content-title="1" /></ac:link> It uses a standard
+JSP approach and framework&lt;&lt;BR&gt;&gt;<br />
+<ac:link><ri:page ri:content-title="2" /></ac:link> It does not require
+custom servlets&lt;&lt;BR&gt;&gt;<br />
+<ac:link><ri:page ri:content-title="3" /></ac:link> It can easily be
+customized/changed by simply changing the error handler definition in the
+web.xml&lt;&lt;BR&gt;&gt;</p>
+
+<p>To implement this method perform the following steps</p>
+
+<p><ac:link><ri:page ri:content-title="1" /></ac:link> define an error
+handling web page in web.xml</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    <error-page>
+        <error-code>500</error-code>
+        <location>/ErrorDisplay.jsf</location>
+    </error-page>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p><ac:link><ri:page ri:content-title="2" /></ac:link> Create the error
+handler display. Due to a problem with the JSF 1.1 specification, the error
+handling page cannot use a &lt;f:view&gt; but must use a subview.</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
+<f:subview id="error"
+    xmlns:f="http://java.sun.com/jsf/core"
+    xmlns:t="http://myfaces.apache.org/tomahawk"
+    xmlns:h="http://java.sun.com/jsf/html"></p>
+<p><html>
+<head>
+    <meta content="no-cache" http-equiv="Cache-Control" />
+    <meta content="no-cache" http-equiv="Pragma" />
+    <title>CMS - Error</title>
+    <t:stylesheet path="#{SessionBean.styleSheet}" />
+    </head>
+    <body>
+    <h:form>
+       :
+       : set up the normal view
+       :
+       <h:outputText styleClass="infoMessage" escape="false"
+value="#{ErrorDisplay.infoMessage}" />
+       <t:htmlTag value="br" />
+       <h:inputTextarea style="width: 99%;" rows="10" readonly="true"
+value="#{ErrorDisplay.stackTrace}" />
+       :
+       : more view stuff
+       :
+    </h:form>
+    </body>
+</html>
+</f:subview></p>
+<p>]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p><ac:link><ri:page ri:content-title="3" /></ac:link> Create a backing
+bean in request scope which can process the error. (don't forget to
+register it on faces-config.xml)</p>
+
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">ErrorDisplay.java</ac:parameter><ac:plain-text-body>&lt;![CDATA[</p>
+<p>import cms.beans.framework.AbstractUIBean;</p>
+<p>import com.c2gl.jsf.framework.ApplicationResource;</p>
+<p>import java.io.PrintWriter;
+import java.io.StringWriter;</p>
+<p>import java.util.Map;</p>
+<p>import javax.faces.context.FacesContext;</p>
+<p>import javax.servlet.ServletException;</p>
+<p>public class ErrorDisplay extends AbstractUIBean {
+    private static final long serialVersionUID = 3123969847287207137L;
+    private static final String BEAN_NAME = ErrorDisplay.class.getName();</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">String</span> <span class="n">getInfoMessage</span><span class="p">()</span> <span class="p">{</span>
+<span class="k">return</span> &quot;<span class="n">An</span> <span class="n">unexpected</span> <span class="n">processing</span> <span class="n">error</span> <span class="n">has</span> <span class="n">occurred</span><span class="p">.</span> <span class="n">Please</span> <span class="n">cut</span> <span class="n">and</span>
+</pre></div>
+
+
+<p>paste the following information" + " into an email and send it to <b>" +
+    some email address + "</b>. If this error " + "continues to occur
+please contact our technical support staff at <b>" +
+    some phone number etc + "</b>.";
+    }</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">String</span> <span class="n">getStackTrace</span><span class="p">()</span> <span class="p">{</span>
+<span class="n">FacesContext</span> <span class="n">context</span> <span class="p">=</span> <span class="n">FacesContext</span><span class="p">.</span><span class="n">getCurrentInstance</span><span class="p">();</span>
+<span class="n">Map</span> <span class="n">requestMap</span> <span class="p">=</span> <span class="n">context</span><span class="p">.</span><span class="n">getExternalContext</span><span class="p">().</span><span class="n">getRequestMap</span><span class="p">();</span>
+<span class="n">Throwable</span> <span class="n">ex</span> <span class="p">=</span> <span class="p">(</span><span class="n">Throwable</span><span class="p">)</span>
+</pre></div>
+
+
+<p>requestMap.get("javax.servlet.error.exception");</p>
+<div class="codehilite"><pre><span class="n">StringWriter</span> <span class="n">writer</span> <span class="p">=</span> <span class="n">new</span> <span class="n">StringWriter</span><span class="p">();</span>
+<span class="n">PrintWriter</span> <span class="n">pw</span> <span class="p">=</span> <span class="n">new</span> <span class="n">PrintWriter</span><span class="p">(</span><span class="n">writer</span><span class="p">);</span>
+<span class="n">fillStackTrace</span><span class="p">(</span><span class="n">ex</span><span class="p">,</span> <span class="n">pw</span><span class="p">);</span>
+
+<span class="k">return</span> <span class="n">writer</span><span class="p">.</span><span class="n">toString</span><span class="p">();</span>
+<span class="p">}</span>
+
+<span class="n">private</span> <span class="n">void</span> <span class="n">fillStackTrace</span><span class="p">(</span><span class="n">Throwable</span> <span class="n">ex</span><span class="p">,</span> <span class="n">PrintWriter</span> <span class="n">pw</span><span class="p">)</span> <span class="p">{</span>
+<span class="k">if</span> <span class="p">(</span><span class="n">null</span> <span class="o">==</span> <span class="n">ex</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">return</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="n">ex</span><span class="p">.</span><span class="n">printStackTrace</span><span class="p">(</span><span class="n">pw</span><span class="p">);</span>
+
+<span class="k">if</span> <span class="p">(</span><span class="n">ex</span> <span class="n">instanceof</span> <span class="n">ServletException</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">Throwable</span> <span class="n">cause</span> <span class="p">=</span> <span class="p">((</span><span class="n">ServletException</span><span class="p">)</span> <span class="n">ex</span><span class="p">).</span><span class="n">getRootCause</span><span class="p">();</span>
+
+    <span class="k">if</span> <span class="p">(</span><span class="n">null</span> !<span class="p">=</span> <span class="n">cause</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">pw</span><span class="p">.</span><span class="n">println</span><span class="p">(</span>&quot;<span class="n">Root</span> <span class="n">Cause</span><span class="p">:</span>&quot;<span class="p">);</span>
+    <span class="n">fillStackTrace</span><span class="p">(</span><span class="n">cause</span><span class="p">,</span> <span class="n">pw</span><span class="p">);</span>
+    <span class="p">}</span>
+<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+    <span class="n">Throwable</span> <span class="n">cause</span> <span class="p">=</span> <span class="n">ex</span><span class="p">.</span><span class="n">getCause</span><span class="p">();</span>
+
+    <span class="k">if</span> <span class="p">(</span><span class="n">null</span> !<span class="p">=</span> <span class="n">cause</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">pw</span><span class="p">.</span><span class="n">println</span><span class="p">(</span>&quot;<span class="n">Cause</span><span class="p">:</span>&quot;<span class="p">);</span>
+    <span class="n">fillStackTrace</span><span class="p">(</span><span class="n">cause</span><span class="p">,</span> <span class="n">pw</span><span class="p">);</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>}</p>
+<p>]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>Also have a look at our ExceptionUtils class. It encapsulates the way
+how to get the real root cause</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>java</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    <a href="1.html">1</a>
+ List exceptions = ExceptionUtils.getExceptions(exception);
+    <a href="2.html">2</a>
+ Throwable throwable = (Throwable) exceptions.get(exceptions.size()-1);
+    <a href="3.html">3</a>
+ String exceptionMessage = ExceptionUtils.getExceptionMessage(exceptions);
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p><ac:link><ri:page ri:content-title="1" /></ac:link> get a list of all
+exceptions - using getRootCause if available or
+getCause&lt;&lt;BR&gt;&gt;<br />
+<ac:link><ri:page ri:content-title="2" /></ac:link> get the initial
+exception&lt;&lt;BR&gt;&gt;<br />
+<ac:link><ri:page ri:content-title="3" /></ac:link> get the first exception
+with an message starting with the initial exception</p>
+
+<p>So the new fillStackTrace become</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>java</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    private void fillStackTrace(Throwable ex, PrintWriter pw)
+    {
+    if (null == ex) {
+        return;
+    }</p>
+<div class="codehilite"><pre><span class="n">List</span> <span class="n">exceptions</span> <span class="p">=</span> <span class="n">ExceptionUtils</span><span class="p">.</span><span class="n">getExceptions</span><span class="p">(</span><span class="n">exception</span><span class="p">);</span>
+<span class="n">Throwable</span> <span class="n">throwable</span> <span class="p">=</span> <span class="p">(</span><span class="n">Throwable</span><span class="p">)</span>
+</pre></div>
+
+
+<p>exceptions.get(exceptions.size()-1);</p>
+<div class="codehilite"><pre><span class="k">for</span> <span class="p">(</span><span class="n">int</span> <span class="nb">i</span> <span class="p">=</span> 0<span class="p">;</span> <span class="nb">i</span><span class="o">&lt;</span><span class="n">exceptions</span><span class="p">.</span><span class="nb">size</span><span class="p">();</span> <span class="nb">i</span><span class="o">++</span><span class="p">)</span>
+<span class="p">{</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nb">i</span> <span class="o">&gt;</span> 0<span class="p">)</span>
+    <span class="p">{</span>
+    <span class="n">pw</span><span class="p">.</span><span class="n">println</span><span class="p">(</span>&quot;<span class="n">Cause</span><span class="p">:</span>&quot;<span class="p">);</span>
+    <span class="p">}</span>
+    <span class="n">throwable</span><span class="p">.</span><span class="n">printStackTrace</span><span class="p">(</span><span class="n">pw</span><span class="p">);</span>
+<span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>In the backing bean we construct a message which informs the user that
+something we didnt't plan for has happened with directions on who to call,
+what to do etc. We don't really care if they actually do cut-and-paste the
+error and email it to us as it is also in Tomcat's logs but giving the user
+something to do and become part of resolving the problem is always a good
+idea <ac:emoticon ac:name="smile" /></p>
+
+<h4>ViewExpiredException: No saved view state could be found for the view
+identifier</h4>
+
+<p>In some configurations, you might run into this problem exception with
+the error handling method shown above. This will happen if an error results
+in a forward, rather than redirect. The ''ViewHandler'' will call
+''response.sendError()'' in case of an error, which will lookup your
+''&lt;error-page&gt;'' declarations in ''web.xml'' and forward to the error
+url. If the error url is picked up by the ''FacesServlet'' (i.e. it's a JSF
+url), a new JSF lifecycle will be started. However, since this is a
+forward, the request object will still contain all of the request
+parameters, including ''&quot;javax.faces.ViewState&quot;'', which makes
+the request look like a postback to the ''ViewHandler''. Since it's a
+postback, the ''ViewHandler'' will expect a saved view, which is clearly
+not going to be there, since our ''viewId'' is now referencing the error
+page.</p>
+
+<p>This problem can be solved by customizing the ''ViewHandler'' to use
+''response.sendRedirect()'' instead of ''response.sendError()'', but that
+will mean that we can no longer use ''web.xml'' for specifying the error
+page mappings.</p>
+
+<p>Another way to handle this would be to use an intermediate step by
+specifying a non-JSF URL as the error page and then somehow redirecting to
+the JSF error page. For example, for the 404 error code you could specify
+''/error/404_redirect.html'':</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+<html><head><meta http-equiv="Refresh" content="0;
+URL=/DPSV4/error/404.jsf"></head></html>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>This works, but requires you to hard code the context path.</p>
+
+<p>The solution I ended up with involves a ''RedirectServlet'':</p>
+
+<p><ac:macro ac:name="code"><ac:parameter
+ac:name="title">RedirectServlet.java</ac:parameter><ac:plain-text-body>&lt;![CDATA[
+public class RedirectServlet extends HttpServlet {
+    private static final String URL_PREFIX = "url=";</p>
+<div class="codehilite"><pre><span class="p">@</span><span class="n">Override</span>
+<span class="n">protected</span> <span class="n">void</span> <span class="n">doGet</span><span class="p">(</span><span class="n">HttpServletRequest</span> <span class="n">req</span><span class="p">,</span> <span class="n">HttpServletResponse</span>
+</pre></div>
+
+
+<p>resp) throws ServletException, IOException {
+        String query = req.getQueryString();
+        if ( query.contains(URL_PREFIX) ) {
+            String url = query.replace(URL_PREFIX, "");
+            if ( !url.startsWith(req.getContextPath()) ) {
+                url = req.getContextPath() + url;
+            }</p>
+<div class="codehilite"><pre>    <span class="n">resp</span><span class="p">.</span><span class="n">sendRedirect</span><span class="p">(</span><span class="n">url</span><span class="p">);</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+
+<span class="p">@</span><span class="n">Override</span>
+<span class="n">protected</span> <span class="n">void</span> <span class="n">doPost</span><span class="p">(</span><span class="n">HttpServletRequest</span> <span class="n">req</span><span class="p">,</span> <span class="n">HttpServletResponse</span>
+</pre></div>
+
+
+<p>resp) throws ServletException, IOException {
+        doGet(req, resp);
+    }</p>
+<p>}</p>
+<p>]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>used like this in ''web.xml'':</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    <servlet>
+        <servlet-name>Redirect Servlet</servlet-name></p>
+<p><servlet-class>ca.gc.agr.ops.web.jsf.redirect.RedirectServlet</servlet-class>
+    </servlet>  <br />
+    <servlet-mapping>
+        <servlet-name>Redirect Servlet</servlet-name>
+        <url-pattern>/redirect</url-pattern>
+    </servlet-mapping></p>
+<div class="codehilite"><pre><span class="nt">&lt;error-page&gt;</span>
+    <span class="nt">&lt;error-code&gt;</span>403<span class="nt">&lt;/error-code&gt;</span>
+    <span class="nt">&lt;location&gt;</span>/redirect?url=/error/403.jsf<span class="nt">&lt;/location&gt;</span>
+<span class="nt">&lt;/error-page&gt;</span>
+<span class="nt">&lt;error-page&gt;</span>
+    <span class="nt">&lt;error-code&gt;</span>404<span class="nt">&lt;/error-code&gt;</span>
+    <span class="nt">&lt;location&gt;</span>/redirect?url=/error/404.jsf<span class="nt">&lt;/location&gt;</span>
+<span class="nt">&lt;/error-page&gt;</span>
+<span class="nt">&lt;error-page&gt;</span>
+    <span class="nt">&lt;error-code&gt;</span>500<span class="nt">&lt;/error-code&gt;</span>
+    <span class="nt">&lt;location&gt;</span>/redirect?url=/error/500.jsf<span class="nt">&lt;/location&gt;</span>
+<span class="nt">&lt;/error-page&gt;</span>
+</pre></div>
+
+
+<p>]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<h3>With plain JSP </h3>
+
+<p>If you didn't require any JSF functionality in your JSP page it might be
+worth to consider using the following error.jsp</p>
+
+<p>[<a href="http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/error.jsp?view=markup">http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/error.jsp?view=markup</a>](<a-href="http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/error.jsp?view=markup">http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/error.jsp?view=markup</a>.html)
+</p>
+
+<p>with this web.xml configuration</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+    <error-page>
+        <error-code>500</error-code>
+        <location>/error.jsp</location>
+    </error-page>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>This reduces the number of technologies required to show the error page
+which might improve the availablity of this page <ac:emoticon
+ac:name="wink" /></p>
+
+<h3>Custom error handler under Apache Geronimo JavaEE server</h3>
+
+<p>If you would use your own error handler
+(org.apache.myfaces.ERROR_REDIRECT_ALTERNATE_HANDLER) under Apache
+Geronimo, you must set properly your deployment plan (geronimo-web.xml
+usualy), otherwise you will have classloading problem of your class. By
+default the MyFaces classes are loaded to your classpath through
+dependencies at org.apache.geronimo.framework.jee-specs/CAR. This is OK for
+common cases, but if you instruct MyFaces to use your own error handler
+class, you get the error because MyFaces cannot find your class in calling
+class.forName(). Avoid this situation is quite simple - in your deployment
+plan specify dependencies on myfaces-api and myfaces-impl and then modify
+classloading via hidden-classes setting.</p>
+
+<p>A fragment of your dependency plan would be like this:</p>
+
+<p><ac:macro
+ac:name="code"><ac:default-parameter>xml</ac:default-parameter><ac:plain-text-body>&lt;![CDATA[
+<dep:dependencies>
+.
+.
+    <dep:dependency>
+        <dep:groupId>org.apache.myfaces.core</dep:groupId>
+        <dep:artifactId>myfaces-api</dep:artifactId>
+        <dep:type>jar</dep:type>
+    </dep:dependency>
+    <dep:dependency>
+        <dep:groupId>org.apache.myfaces.core</dep:groupId>
+        <dep:artifactId>myfaces-impl</dep:artifactId>
+        <dep:type>jar</dep:type>
+    </dep:dependency>
+.
+.
+</dep:dependencies></p>
+<p><dep:hidden-classes>
+    <dep:filter>javax.faces</dep:filter>
+    <dep:filter>org.apache.myfaces</dep:filter>
+</dep:hidden-classes>
+]
+]&gt;</ac:plain-text-body></ac:macro></p>
+<p>This solution was tested under Apache Geronimo 2.1.3., but will probably
+be similar in other versions.</p>
+
+<p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body>&lt;![CDATA<a href="cdata[{scrollbar}.html">{scrollbar}</a>
+]&gt;</ac:plain-text-body></ac:macro></p></div></div>
+      <div class="clear"></div>
+    </div>
+
+    <div id="copyright" class="container_16">
+      <p>Copyright &#169; 2011 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation.</p>
+    </div>
+  </body>
+</html>