Save This Page
Home » mojarra-1.2_09-b02-FCS-source » com.sun.faces.application » [javadoc | source]
    1   /*
    2    * $Id: ActionListenerImpl.java,v 1.25 2007/04/27 22:00:53 ofung Exp $
    3    */
    4   
    5   /*
    6    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    7    * 
    8    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   
   41   package com.sun.faces.application;
   42   
   43   import javax.faces.FacesException;
   44   import javax.faces.application.Application;
   45   import javax.faces.application.NavigationHandler;
   46   import javax.faces.component.ActionSource;
   47   import javax.faces.component.UIComponent;
   48   import javax.faces.context.FacesContext;
   49   import javax.faces.el.EvaluationException;
   50   import javax.faces.el.MethodBinding;
   51   import javax.faces.el.MethodNotFoundException;
   52   import javax.faces.event.ActionEvent;
   53   import javax.faces.event.ActionListener;
   54   
   55   import java.util.logging.Level;
   56   import java.util.logging.Logger;
   57   import java.text.MessageFormat;
   58   
   59   import com.sun.faces.util.Util;
   60   import com.sun.faces.util.FacesLogger;
   61   
   62   /**
   63    * This action listener implementation processes action events during the
   64    * <em>Apply Request Values</em> or <em>Invoke Application</em>
   65    * phase of the request processing lifecycle (depending upon the
   66    * <code>immediate</code> property of the {@link ActionSource} that
   67    * queued this event.  It invokes the specified application action method,
   68    * and uses the logical outcome value to invoke the default navigation handler
   69    * mechanism to determine which view should be displayed next.</p>
   70    */
   71   public class ActionListenerImpl implements ActionListener {
   72   
   73   
   74       // Log instance for this class
   75       private static final Logger LOGGER = FacesLogger.APPLICATION.getLogger();
   76   
   77   
   78       // --------------------------------------------- Methods From ActionListener
   79   
   80    
   81   
   82       @SuppressWarnings("deprecation")
   83       public void processAction(ActionEvent event) {
   84   
   85           if (LOGGER.isLoggable(Level.FINE)) {
   86               LOGGER.fine(MessageFormat.format("processAction({0})",
   87                                                event.getComponent().getId()));
   88           }
   89           UIComponent source = event.getComponent();
   90           ActionSource actionSource = (ActionSource) source;
   91           FacesContext context = FacesContext.getCurrentInstance();
   92   
   93           Application application = context.getApplication();
   94   
   95           Object invokeResult;
   96           String outcome = null;
   97           MethodBinding binding;
   98   
   99           binding = actionSource.getAction();
  100           if (binding != null) {
  101               try {
  102                   if (null != (invokeResult = binding.invoke(context, null))) {
  103                       outcome = invokeResult.toString();
  104                   }
  105                   // else, default to null, as assigned above.
  106               } catch (MethodNotFoundException e) {
  107                   if (LOGGER.isLoggable(Level.SEVERE)) {
  108                       LOGGER.log(Level.SEVERE, e.getMessage(), e);
  109                   }
  110                   throw new FacesException
  111                         (binding.getExpressionString() + ": " + e.getMessage(),
  112                          e);
  113               }
  114               catch (EvaluationException e) {
  115                   if (LOGGER.isLoggable(Level.SEVERE)) {
  116                       LOGGER.log(Level.SEVERE, e.getMessage(), e);
  117                   }
  118                   throw new FacesException
  119                         (binding.getExpressionString() + ": " + e.getMessage(),
  120                          e);
  121               }
  122           }
  123   
  124           // Retrieve the NavigationHandler instance..
  125   
  126           NavigationHandler navHandler = application.getNavigationHandler();
  127   
  128           // Invoke nav handling..
  129   
  130           navHandler.handleNavigation(context,
  131                                       (null != binding) ?
  132                                       binding.getExpressionString() : null,
  133                                       outcome);
  134   
  135           // Trigger a switch to Render Response if needed
  136           context.renderResponse();
  137   
  138       }
  139   
  140   }

Save This Page
Home » mojarra-1.2_09-b02-FCS-source » com.sun.faces.application » [javadoc | source]