Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/myfaces/application/ActionListenerImpl.java


1   /*
2    * Copyright 2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.myfaces.application;
17  
18  import javax.faces.FacesException;
19  import javax.faces.application.Application;
20  import javax.faces.application.NavigationHandler;
21  import javax.faces.component.ActionSource;
22  import javax.faces.context.FacesContext;
23  import javax.faces.el.EvaluationException;
24  import javax.faces.el.MethodBinding;
25  import javax.faces.event.AbortProcessingException;
26  import javax.faces.event.ActionEvent;
27  import javax.faces.event.ActionListener;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  
32  
33  /**
34   * @author Manfred Geiler (latest modification by $Author: mbr $)
35   * @author Anton Koinov
36   * @version $Revision: 231425 $ $Date: 2005-08-11 07:49:45 -0400 (Thu, 11 Aug 2005) $
37   */
38  public class ActionListenerImpl
39      implements ActionListener
40  {
41      private static final Log log = LogFactory.getLog(ActionListenerImpl.class);
42  
43      public void processAction(ActionEvent actionEvent) throws AbortProcessingException
44      {
45          FacesContext facesContext = FacesContext.getCurrentInstance();
46          Application application = facesContext.getApplication();
47  
48          ActionSource actionSource = (ActionSource)actionEvent.getComponent();
49          MethodBinding methodBinding = actionSource.getAction();
50  
51          String fromAction;
52          String outcome;
53          if (methodBinding == null)
54          {
55              fromAction = null;
56              outcome = null;
57          }
58          else
59          {
60              fromAction = methodBinding.getExpressionString();
61              try
62              {
63                  outcome = (String) methodBinding.invoke(facesContext, null);
64              }
65              catch (EvaluationException e)
66              {
67                  Throwable cause = e.getCause();
68                  if (cause != null && cause instanceof AbortProcessingException)
69                  {
70                      throw (AbortProcessingException)cause;
71                  }
72                  else
73                  {
74                      throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e);
75                  }
76              }
77              catch (RuntimeException e)
78              {
79                  throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e);
80              }
81          }
82  
83          NavigationHandler navigationHandler = application.getNavigationHandler();
84          navigationHandler.handleNavigation(facesContext,
85                                             fromAction,
86                                             outcome);
87      //Render Response if needed
88      facesContext.renderResponse();
89  
90      }
91  }