incubator-adffaces-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Carlson <carlso...@llnl.gov>
Subject action-listener defined in faces-config.xml
Date Fri, 21 Dec 2007 23:43:29 GMT
package gov.llnl.nif.dataviz.actionlistener.exceptionhandler;

import java.sql.SQLException;

import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;

import oracle.toplink.essentials.exceptions.DatabaseException;

import org.apache.log4j.Logger;
import org.apache.myfaces.application.ActionListenerImpl;

public class ExceptionHandlingActionListener extends ActionListenerImpl {
	 private static Logger log = Logger.getLogger(ExceptionHandlingActionListener.class);

	  public String oneLiner(String s) {
		  String [] lines = s.split("[\r\n]+");
		  StringBuilder sb = new StringBuilder();
		  for (String line : lines) {
			  sb.append(line);
		  }
		  return sb.toString();
	  }
	  public void processAction(ActionEvent event) throws AbortProcessingException {
	    FacesContext facesContext = FacesContext.getCurrentInstance();
	    try {

	      super.processAction(event);
	    } catch (Exception fe) {      
	      Throwable databaseException = ExceptionUtils.getException(fe, DatabaseException.class);
	      if (databaseException != null) {
	       FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Database
Error",oneLiner(databaseException.getMessage()));
	       facesContext.addMessage(null, facesMessage);
	      } else {
	    	  databaseException = ExceptionUtils.getException(fe, SQLException.class);
	          if (databaseException != null) {
	        	  FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, "SQL
Database error", oneLiner(databaseException.getMessage()));
	        	  facesContext.addMessage(null, facesMessage);
	          } else {
	        	  throw new FacesException(fe);
	          }
	       }
	    }
	  }

}

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message