1 5 package org.exoplatform.faces.core.component; 6 7 import java.io.*; 8 import javax.faces.context.FacesContext; 9 import javax.faces.context.ResponseWriter; 10 import org.exoplatform.faces.FacesConstants; 11 import org.exoplatform.faces.context.PortletFacesContext; 12 18 public class UIFatalError extends UIExoComponentBase { 19 20 private Throwable exception_ ; 21 22 public UIFatalError(Throwable ex) { 23 setId("UIFatalError") ; 24 exception_ = ex ; 25 } 26 27 public void decode(FacesContext context) { 28 PortletFacesContext pcontext = (PortletFacesContext)context ; 29 pcontext.destroy() ; 30 } 31 32 final public void encodeBegin(FacesContext context) throws IOException { 33 String baseURL = context.getExternalContext().encodeActionURL(null) ; 34 ResponseWriter w = context.getResponseWriter() ; 35 w.write("<div>"); 36 w. write("The portlet has a fatal error. Click here to restart the portlet") ; 37 renderButton(w, baseURL); 38 w.write("</div>"); 39 w.write("<div style='border: 1px dashed black>"); 40 String message = exception_.getMessage() ; 41 if (message != null) { 42 w.write(exception_.getMessage()) ; 43 } 44 w.write(getStackTrace(exception_)); 45 w.write("</div>"); 46 47 } 48 49 private void renderButton(ResponseWriter w, String baseURL) throws IOException { 50 w.write("<a HREF='"); w.write(baseURL) ; 51 w.write('&'); w.write(FacesConstants.ACTION); w.write("=restart") ; 52 w.write("'>"); 53 w.write("Click"); 54 w.write("</a>") ; 55 } 56 57 private String getStackTrace(Throwable t) { 58 ByteArrayOutputStream ostream = new ByteArrayOutputStream() ; 59 PrintStream pstream = new PrintStream(ostream) ; 60 t.printStackTrace(pstream) ; 61 return new String (ostream.toByteArray()) ; 62 } 63 64 final public void encodeChildren(FacesContext context) throws IOException { 65 } 66 67 final public void encodeEnd(FacesContext context) throws IOException { 68 } 69 } | Popular Tags |