1 16 package org.apache.myfaces.renderkit.html.ext; 17 18 import org.apache.myfaces.component.html.ext.HtmlMessage; 19 import org.apache.myfaces.component.html.ext.HtmlMessages; 20 import org.apache.myfaces.renderkit.html.HtmlMessagesRendererBase; 21 22 import javax.faces.application.FacesMessage; 23 import javax.faces.component.UIComponent; 24 import javax.faces.context.FacesContext; 25 import java.io.IOException ; 26 import java.text.MessageFormat ; 27 28 51 public class HtmlMessagesRenderer 52 extends HtmlMessagesRendererBase 53 { 54 56 57 public void encodeEnd(FacesContext facesContext, UIComponent component) 58 throws IOException 59 { 60 super.encodeEnd(facesContext, component); renderMessages(facesContext, component); 62 } 63 64 protected String getSummary(FacesContext facesContext, 65 UIComponent message, 66 FacesMessage facesMessage, 67 String msgClientId) 68 { 69 String msgSummary = facesMessage.getSummary(); 70 if (msgSummary == null) return null; 71 72 String inputLabel = null; 73 if (msgClientId != null) inputLabel = HtmlMessageRenderer.findInputLabel(facesContext, msgClientId); 74 if (inputLabel == null) inputLabel = ""; 75 76 if(((message instanceof HtmlMessages && ((HtmlMessages) message).isReplaceIdWithLabel()) || 77 (message instanceof HtmlMessage && ((HtmlMessage) message).isReplaceIdWithLabel()))&& 78 inputLabel.length()!=0) 79 msgSummary = msgSummary.replaceAll(HtmlMessageRenderer.findInputId(facesContext, msgClientId),inputLabel); 80 81 82 String summaryFormat; 83 if (msgClientId == null) 84 { 85 summaryFormat = getGlobalSummaryFormat(message); 86 if (summaryFormat == null) 87 { 88 summaryFormat = getSummaryFormat(message); 89 } 90 } 91 else 92 { 93 summaryFormat = getSummaryFormat(message); 94 } 95 if (summaryFormat == null) return msgSummary; 96 97 MessageFormat format = new MessageFormat (summaryFormat, facesContext.getViewRoot().getLocale()); 98 return format.format(new Object [] {msgSummary, inputLabel}); 99 } 100 101 102 private String getSummaryFormat(UIComponent message) 103 { 104 if (message instanceof HtmlMessages) 105 { 106 return ((HtmlMessages)message).getSummaryFormat(); 107 } 108 else 109 { 110 return (String )message.getAttributes().get("summaryFormat"); 111 } 112 } 113 114 private String getGlobalSummaryFormat(UIComponent message) 115 { 116 if (message instanceof HtmlMessages) 117 { 118 return ((HtmlMessages)message).getGlobalSummaryFormat(); 119 } 120 else 121 { 122 return (String )message.getAttributes().get("globalSummaryFormat"); 123 } 124 } 125 126 protected String getDetail(FacesContext facesContext, 127 UIComponent message, 128 FacesMessage facesMessage, 129 String msgClientId) 130 { 131 String msgDetail = facesMessage.getDetail(); 132 if (msgDetail == null) return null; 133 134 String inputLabel = null; 135 if (msgClientId != null) inputLabel = HtmlMessageRenderer.findInputLabel(facesContext, msgClientId); 136 if (inputLabel == null) inputLabel = ""; 137 138 if(((message instanceof HtmlMessages && ((HtmlMessages) message).isReplaceIdWithLabel()) || 139 (message instanceof HtmlMessage && ((HtmlMessage) message).isReplaceIdWithLabel()))&& 140 inputLabel.length()!=0) 141 msgDetail = msgDetail.replaceAll(HtmlMessageRenderer.findInputId(facesContext, msgClientId),inputLabel); 142 143 String detailFormat; 144 if (message instanceof HtmlMessage) 145 { 146 detailFormat = ((HtmlMessage)message).getDetailFormat(); 147 } 148 else 149 { 150 detailFormat = (String )message.getAttributes().get("detailFormat"); 151 } 152 153 if (detailFormat == null) return msgDetail; 154 155 MessageFormat format = new MessageFormat (detailFormat, facesContext.getViewRoot().getLocale()); 156 return format.format(new Object [] {msgDetail, inputLabel}); 157 } 158 159 160 } 161 | Popular Tags |