1 5 package org.exoplatform.faces.core.event; 6 7 import java.util.ResourceBundle ; 8 import javax.faces.application.FacesMessage; 9 import javax.faces.component.UIComponent; 10 import org.exoplatform.commons.exception.UniqueObjectException; 11 import org.exoplatform.faces.core.Util; 12 import org.exoplatform.faces.core.component.InformationProvider; 13 19 public class UniqueObjectExceptionHandler extends ExceptionHandler { 20 public boolean showStackTrace_ = false ; 21 22 public UniqueObjectExceptionHandler() { 23 } 24 25 public UniqueObjectExceptionHandler setShowStackTrace(boolean b) { 26 showStackTrace_ = b ; 27 return this ; 28 } 29 30 public boolean canHandleError(Throwable error) { 31 return error instanceof UniqueObjectException ; 32 } 33 34 public void handle(ExoActionEvent action, Throwable error) { 35 UniqueObjectException ex = (UniqueObjectException) error ; 36 UIComponent src = action.getComponent() ; 37 InformationProvider iprovider = Util.findInformationProvider(src) ; 38 if(iprovider != null) { 39 ResourceBundle res = Util.getApplicationResourceBundle() ; 40 String messageKey = ex.getMessageKey() ; 41 String message = this.getResource(res, messageKey) ; 42 if(message == null) { 43 message = "No explaination is found for the key: " + messageKey ; 44 } 45 iprovider.addMessage(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, ex.getExceptionDescription())) ; 46 iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ; 47 } 48 } 49 } | Popular Tags |