KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > common > renderer > ErrorsRenderer


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.common.renderer;
18
19 import java.io.IOException JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import javax.faces.application.FacesMessage;
23 import javax.faces.component.UIComponent;
24 import javax.faces.context.FacesContext;
25 import javax.faces.context.ResponseWriter;
26 import javax.faces.el.ValueBinding;
27
28 import org.alfresco.web.app.Application;
29 import org.alfresco.web.ui.common.PanelGenerator;
30 import org.alfresco.web.ui.common.Utils;
31
32 /**
33  * Renderer that displays any errors that occurred in the previous lifecylce
34  * processing within a gradient panel
35  *
36  * @author gavinc
37  */

38 public class ErrorsRenderer extends BaseRenderer
39 {
40    private static final String JavaDoc DEFAULT_MESSAGE = "wizard_errors";
41    
42    /**
43     * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
44     */

45    public void encodeBegin(FacesContext context, UIComponent component) throws IOException JavaDoc
46    {
47       if (component.isRendered() == false)
48       {
49          return;
50       }
51       
52       Iterator JavaDoc messages = context.getMessages();
53       if (messages.hasNext())
54       {
55          ResponseWriter out = context.getResponseWriter();
56          String JavaDoc contextPath = context.getExternalContext().getRequestContextPath();
57          String JavaDoc styleClass = (String JavaDoc)component.getAttributes().get("styleClass");
58          String JavaDoc message = (String JavaDoc)component.getAttributes().get("message");
59          
60          if (message == null)
61          {
62             // because we are using the standard messages component value binding
63
// would not be handled for the message attribute so do it here
64
ValueBinding vb = component.getValueBinding("message");
65             if (vb != null)
66             {
67                message = (String JavaDoc)vb.getValue(context);
68             }
69             
70             if (message == null)
71             {
72                message = Application.getMessage(context, DEFAULT_MESSAGE);
73             }
74          }
75          
76          PanelGenerator.generatePanelStart(out, contextPath, "yellowInner", "#ffffcc");
77          
78          out.write("\n<div");
79          if (styleClass != null)
80          {
81             outputAttribute(out, styleClass, "class");
82          }
83          out.write(">");
84          out.write("<img SRC='");
85          out.write(contextPath);
86          out.write("/images/icons/info_icon.gif' alt='Error' align='absmiddle'/>&nbsp;&nbsp;");
87          out.write(Utils.encode(message));
88          out.write("\n<ul style='margin:2px;'>");
89          
90          while (messages.hasNext())
91          {
92             FacesMessage fm = (FacesMessage)messages.next();
93             out.write("<li>");
94             out.write(Utils.encode(fm.getSummary()));
95             out.write("</li>\n");
96          }
97          
98          out.write("</ul></div>\n");
99          
100          PanelGenerator.generatePanelEnd(out, contextPath, "yellowInner");
101          
102          // TODO: Expose this as a configurable attribute i.e. padding at bottom
103
out.write("<div style='padding:2px;'></div>");
104       }
105    }
106
107    /**
108     * @see javax.faces.render.Renderer#getRendersChildren()
109     */

110    public boolean getRendersChildren()
111    {
112       return false;
113    }
114 }
115
Popular Tags