1 17 package org.alfresco.web.ui.common.renderer; 18 19 import java.io.IOException ; 20 import java.util.Iterator ; 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 38 public class ErrorsRenderer extends BaseRenderer 39 { 40 private static final String DEFAULT_MESSAGE = "wizard_errors"; 41 42 45 public void encodeBegin(FacesContext context, UIComponent component) throws IOException 46 { 47 if (component.isRendered() == false) 48 { 49 return; 50 } 51 52 Iterator messages = context.getMessages(); 53 if (messages.hasNext()) 54 { 55 ResponseWriter out = context.getResponseWriter(); 56 String contextPath = context.getExternalContext().getRequestContextPath(); 57 String styleClass = (String )component.getAttributes().get("styleClass"); 58 String message = (String )component.getAttributes().get("message"); 59 60 if (message == null) 61 { 62 ValueBinding vb = component.getValueBinding("message"); 65 if (vb != null) 66 { 67 message = (String )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'/> "); 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 out.write("<div style='padding:2px;'></div>"); 104 } 105 } 106 107 110 public boolean getRendersChildren() 111 { 112 return false; 113 } 114 } 115 | Popular Tags |