View Javadoc

1   /*
2    * $Id: AbstractReturnValueActionListener.java,v 1.4 2010/06/16 13:29:40 oeuillot Exp $
3    */
4   package org.rcfaces.core.internal.listener;
5   
6   import javax.el.ELException;
7   import javax.el.MethodExpression;
8   import javax.faces.context.FacesContext;
9   import javax.faces.event.FacesEvent;
10  
11  import org.apache.commons.logging.Log;
12  import org.apache.commons.logging.LogFactory;
13  import org.rcfaces.core.internal.service.IApplicationExceptionCapability;
14  import org.rcfaces.core.internal.service.IEventReturnValue;
15  import org.rcfaces.core.lang.ApplicationException;
16  
17  /**
18   * 
19   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
20   * @version $Revision: 1.4 $ $Date: 2010/06/16 13:29:40 $
21   */
22  public abstract class AbstractReturnValueActionListener extends
23          AbstractActionListener {
24      private static final String REVISION = "$Revision: 1.4 $";
25  
26      private static final Log LOG = LogFactory
27              .getLog(AbstractReturnValueActionListener.class);
28  
29      public AbstractReturnValueActionListener() {
30      }
31  
32      public AbstractReturnValueActionListener(String expression) {
33          super(expression);
34      }
35  
36      public AbstractReturnValueActionListener(String expression,
37              boolean partialRendering) {
38          super(expression, partialRendering);
39      }
40  
41      protected void processReturn(FacesContext facesContext,
42              MethodExpression binding, FacesEvent event, Object ret) {
43          // Pas de traitement de retour !
44  
45          if (LOG.isDebugEnabled()) {
46              LOG.debug("Process return value '" + ret + "'.");
47          }
48  
49          if (ret == null) {
50              return;
51          }
52  
53          if (event instanceof IEventReturnValue) {
54              ((IEventReturnValue) event).setReturnValue(ret);
55          }
56      }
57  
58      protected Exception processException(ELException ex, FacesEvent event) {
59          Throwable cause = ex.getCause();
60  
61          if (event instanceof IApplicationExceptionCapability) {
62              if (cause instanceof ApplicationException) {
63                  ((IApplicationExceptionCapability) event)
64                          .setApplicationException((ApplicationException) cause);
65  
66                  return null;
67              }
68          }
69  
70          return super.processException(ex, event);
71      }
72  
73  }