1 16 package org.apache.myfaces.wap.renderkit.wml; 17 18 import java.util.Iterator ; 19 20 import javax.faces.application.FacesMessage; 21 import javax.faces.component.UIComponent; 22 import javax.faces.context.FacesContext; 23 import javax.faces.context.ResponseWriter; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.myfaces.wap.component.Message; 28 import org.apache.myfaces.wap.renderkit.WmlRenderer; 29 30 38 public class MessageRenderer extends WmlRenderer { 39 private static Log log = LogFactory.getLog(MessageRenderer.class); 40 41 42 public MessageRenderer() { 43 super(); 44 log.debug("created object " + this.getClass().getName()); 45 } 46 47 public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException { 48 log.debug("encodeBegin(" + component.getId() + ")"); 49 if (context == null || component == null) { 50 throw new NullPointerException (); 51 } 52 } 53 54 public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException { 55 log.debug("encodeChildren(" + component.getId() + ")"); 56 if (context == null || component == null) { 57 throw new NullPointerException (); 58 } 59 } 60 61 public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException { 62 log.debug("encodeEnd(" + component.getId() + ")"); 63 if (context == null || component == null) { 64 throw new NullPointerException (); 65 } 66 if (!component.isRendered()) return; 67 68 Message comp = (Message)component; 69 ResponseWriter writer = context.getResponseWriter(); 70 71 String _for = comp.getFor(); 72 if (_for == null) log.error("Attribute 'for' of UIMessage must not be null."); 73 74 UIComponent forComponent = component.findComponent(_for); 75 if (forComponent == null) log.error("Unable to find component '" + _for + "'. Can not render UIMessage component."); 76 77 Iterator iter = context.getMessages(forComponent.getClientId(context)); 78 if (iter.hasNext()) { 79 FacesMessage message = (FacesMessage)iter.next(); 80 if (comp.isShowSummary()) 81 writer.write(message.getSummary()); 82 if (comp.isShowDetail()) 83 writer.write(message.getDetail()); 84 } 85 } 86 87 public void decode(FacesContext context, UIComponent component) { 88 if (component == null ) throw new NullPointerException (); 89 } 90 } 91 92 | Popular Tags |