KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > application > ActionListenerImpl


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 org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21 import javax.faces.application.Application;
22 import javax.faces.application.NavigationHandler;
23 import javax.faces.component.ActionSource;
24 import javax.faces.context.FacesContext;
25 import javax.faces.el.EvaluationException;
26 import javax.faces.el.MethodBinding;
27 import javax.faces.event.AbortProcessingException;
28 import javax.faces.event.ActionEvent;
29 import javax.faces.event.ActionListener;
30
31
32 /**
33  * @author Manfred Geiler (latest modification by $Author: matze $)
34  * @author Anton Koinov
35  * @version $Revision: 1.18 $ $Date: 2004/10/13 11:50:59 $
36  */

37 public class ActionListenerImpl
38     implements ActionListener
39 {
40     private static final Log log = LogFactory.getLog(ActionListenerImpl.class);
41
42     public void processAction(ActionEvent actionEvent) throws AbortProcessingException
43     {
44         FacesContext facesContext = FacesContext.getCurrentInstance();
45         Application application = facesContext.getApplication();
46
47         ActionSource actionSource = (ActionSource)actionEvent.getComponent();
48         MethodBinding methodBinding = actionSource.getAction();
49
50         String JavaDoc fromAction;
51         String JavaDoc outcome;
52         if (methodBinding == null)
53         {
54             fromAction = null;
55             outcome = null;
56         }
57         else
58         {
59             fromAction = methodBinding.getExpressionString();
60             try
61             {
62                 outcome = (String JavaDoc) methodBinding.invoke(facesContext, null);
63             }
64             catch (EvaluationException e)
65             {
66                 Throwable JavaDoc cause = e.getCause();
67                 if (cause != null && cause instanceof AbortProcessingException)
68                 {
69                     throw (AbortProcessingException)cause;
70                 }
71                 else
72                 {
73                     log.error("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e);
74                     throw e;
75                 }
76             }
77             catch (RuntimeException JavaDoc e)
78             {
79                 log.error("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e);
80                 throw e;
81             }
82         }
83
84         NavigationHandler navigationHandler = application.getNavigationHandler();
85         navigationHandler.handleNavigation(facesContext,
86                                            fromAction,
87                                            outcome);
88         //Render Response if needed
89
facesContext.renderResponse();
90
91     }
92 }
93
Popular Tags