1 5 package org.exoplatform.faces.core.component.model; 6 7 import java.io.IOException ; 8 import java.util.ArrayList ; 9 import java.util.List ; 10 import java.util.ResourceBundle ; 11 12 import javax.faces.application.FacesMessage; 13 import javax.faces.context.FacesContext; 14 import javax.faces.context.ResponseWriter; 15 import org.exoplatform.faces.core.component.InformationProvider; 16 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer; 17 import org.exoplatform.faces.core.Util ; 18 import org.exoplatform.faces.application.ExoFacesMessage; 19 25 public class Information { 26 private List messages_ ; 27 28 public Information() { 29 messages_ = new ArrayList (5) ; 30 } 31 32 public boolean hasMessage() { return messages_.size() > 0 ;} 33 public List getMessages() { return messages_ ; } 34 public void addMessage(FacesMessage message) { messages_.add(message) ; } 35 public void clearMessages() { messages_.clear() ; } 36 37 static public void renderBodyInformation(FacesContext context, InformationProvider iprovider) throws IOException { 38 ResponseWriter w = context.getResponseWriter() ; 39 List messages = iprovider.getMessages() ; 40 ResourceBundle res = Util.getApplicationResourceBundle(); 41 w.write("<table width='100%'>") ; 42 for (int i = 0; i < messages.size() ; i++) { 43 ExoFacesMessage m = (ExoFacesMessage) messages.get(i) ; 44 String detail = m.getDetail(res) ; 45 if(detail == null) detail = "" ; 46 w.write("<tr>") ; 47 if(m.getSeverity() == FacesMessage.SEVERITY_ERROR) { 48 w.write("<td class='portlet-msg-error'>") ; 49 w. write("error: ") ; w.write(m.getSummary(res)) ; w.write("<br/>") ; 50 } else if (m.getSeverity() == FacesMessage.SEVERITY_WARN) { 51 w.write("<td class='portlet-msg-alert'>") ; 52 w. write("warning: ") ; w.write(m.getSummary(res)) ; w.write("<br/>") ; 53 } else { 54 w.write("<td class='portlet-msg-info'>") ; 55 w. write("info: ") ; w.write(m.getSummary(res)) ;w.write("<br/>") ; 56 } 57 w. write(detail) ; 58 w. write("</td>") ; 59 w.write("</tr>") ; 60 } 61 w. write("<tr>") ; 62 w. write("<td align='center'>") ; 63 String baseUrl = HtmlBasicRenderer.getBaseURL(context); 64 HtmlBasicRenderer.appendLink(w, "Back", baseUrl, HtmlBasicRenderer.EMPTY_PARAMS, null) ; 65 w. write("<td>") ; 66 w. write("</tr>") ; 67 w.write("</table>") ; 68 iprovider.clearMessages() ; 69 iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ; 70 } 71 72 73 static public void renderFooterInformation(FacesContext context, InformationProvider iprovider) throws IOException { 74 ResponseWriter w = context.getResponseWriter() ; 75 List messages = iprovider.getMessages() ; 76 ResourceBundle res = Util.getApplicationResourceBundle(); 77 w.write("<div style='color: red;'>") ; 78 for (int i = 0; i < messages.size() ; i++) { 79 try { 80 ExoFacesMessage m = (ExoFacesMessage) messages.get(i) ; 81 if(m.getSeverity() == FacesMessage.SEVERITY_ERROR) { 82 w.write("error: ") ; w.write(m.getSummary(res)) ; w.write("<br/>") ; 83 } else if (m.getSeverity() == FacesMessage.SEVERITY_WARN) { 84 w.write("warning: ") ; w.write(m.getSummary(res)) ; w.write("<br/>") ; 85 } else { 86 w.write("info: ") ; w.write(m.getSummary(res)) ;w.write("<br/>") ; 87 } 88 } catch (Throwable t) { t.printStackTrace() ;} 89 } 90 w.write("</div>") ; 91 iprovider.clearMessages() ; 92 iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ; 93 } 94 } 95 | Popular Tags |