javax.faces.event.ActionListener类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(16.2k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中javax.faces.event.ActionListener类的一些代码示例,展示了ActionListener类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ActionListener类的具体详情如下:
包路径:javax.faces.event.ActionListener
类名称:ActionListener

ActionListener介绍

[英]A listener interface for receiving ActionEvents. An implementation of this interface must be thread-safe. A class that is interested in receiving such events implements this interface, and then registers itself with the source UIComponent of interest, by calling addActionListener().
[中]用于接收ActionEvents的侦听器接口。此接口的实现必须是线程安全的。对接收此类事件感兴趣的类实现此接口,然后通过调用addActionListener()向感兴趣的源UIComponent注册自己。

代码示例

代码示例来源:origin: primefaces/primefaces

@Override
public void processAction(ActionEvent event) throws AbortProcessingException {
  UIComponent source = event.getComponent();
  // don't use event#getFacesContext() - it's only available in JSF 2.3
  Map<Object, Object> attrs = FacesContext.getCurrentInstance().getAttributes();
  if (source instanceof Widget) {
    attrs.put(Constants.DIALOG_FRAMEWORK.SOURCE_WIDGET, ((Widget) source).resolveWidgetVar());
  }
  attrs.put(Constants.DIALOG_FRAMEWORK.SOURCE_COMPONENT, source.getClientId());
  base.processAction(event);
}

代码示例来源:origin: org.apache.myfaces.core/myfaces-api

if (context.getResponseComplete())
if (!context.getViewRoot().equals(sourceViewRoot))
  ActionListener defaultActionListener = context.getApplication().getActionListener();
  if (defaultActionListener != null)
    String  viewIdBeforeAction = context.getViewRoot().getViewId();
    Boolean oldBroadcastProcessing = (Boolean) context.getAttributes().
      get(BROADCAST_PROCESSING_KEY);
          defaultActionListener.processAction((ActionEvent) event);
      Integer count = (Integer) context.getAttributes().get(EVENT_COUNT_KEY);
      count = (count == null) ? 0 : count;
      String viewIdAfterAction = context.getViewRoot().getViewId();

代码示例来源:origin: org.richfaces.ui.core/richfaces-ui-core-ui

public void processAction(ActionEvent event) throws AbortProcessingException {
    ActionListener instance = null;
    FacesContext faces = FacesContext.getCurrentInstance();
    if (faces == null) {
      return;
    }

    if (this.binding != null) {
      instance = (ActionListener) binding.getValue(faces.getELContext());
    }

    if (instance == null && this.type != null) {
      try {
        instance = TagHandlerUtils.loadClass(this.type, ActionListener.class).newInstance();
      } catch (Exception e) {
        throw new AbortProcessingException("Couldn't lazily instantiate ActionListener", e);
      }

      if (this.binding != null) {
        binding.setValue(faces.getELContext(), instance);
      }
    }

    if (instance != null) {
      instance.processAction(event);
    }
  }
}

代码示例来源:origin: org.springframework.webflow/org.springframework.faces

public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
  if (!JsfUtils.isFlowRequest()) {
    delegate.processAction(actionEvent);
    return;
  }
  FacesContext context = FacesContext.getCurrentInstance();
  ActionSource source = (ActionSource) actionEvent.getSource();
  String eventId = null;
  if (source.getAction() != null) {
    if (logger.isDebugEnabled()) {
      logger.debug("Invoking action " + source.getAction());
    }
    eventId = (String) source.getAction().invoke(context, null);
  }
  if (StringUtils.hasText(eventId)) {
    if (logger.isDebugEnabled()) {
      logger.debug("Event '" + eventId + "' detected");
    }
    if (source.isImmediate() || validateModel(context, eventId)) {
      context.getExternalContext().getRequestMap().put(JsfView.EVENT_KEY, eventId);
    }
  } else {
    logger.debug("No action event detected");
    context.getExternalContext().getRequestMap().remove(JsfView.EVENT_KEY);
  }
  // tells JSF lifecycle that rendering should now happen and any subsequent phases should be skipped
  // required in the case of this action listener firing immediately (immediate=true) before validation
  context.renderResponse();
}

代码示例来源:origin: org.apache.myfaces.extensions.cdi.modules/myfaces-extcdi-jsf12-module-impl

/**
 * {@inheritDoc}
 */
public void processAction(ActionEvent actionEvent)
{
  if(this.deactivated)
  {
    return;
  }
  
  ViewConfigDescriptor viewConfigDescriptor =
      ViewConfigCache.getViewConfigDescriptor(FacesContext.getCurrentInstance().getViewRoot().getViewId());
  if(viewConfigDescriptor instanceof EditableViewConfigDescriptor)
  {
    ((EditableViewConfigDescriptor)viewConfigDescriptor).invokePrePageActionMethods();
  }
  this.wrapped.processAction(actionEvent);
}

代码示例来源:origin: eclipse-ee4j/mojarra

/**
 * <p>
 * In addition to to the default {@link UIComponent#broadcast} processing, pass the
 * {@link ActionEvent} being broadcast to the method referenced by <code>actionListener</code>
 * (if any), and to the default {@link ActionListener} registered on the
 * {@link javax.faces.application.Application}.
 * </p>
 *
 * @param event {@link FacesEvent} to be broadcast
 *
 * @throws AbortProcessingException Signal the JavaServer Faces implementation that no further
 *             processing on the current event should be performed
 * @throws IllegalArgumentException if the implementation class of this {@link FacesEvent} is
 *             not supported by this component
 * @throws NullPointerException if <code>event</code> is <code>null</code>
 */
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
  // Perform standard superclass processing (including calling our
  // ActionListeners)
  super.broadcast(event);
  if (event instanceof ActionEvent) {
    FacesContext context = event.getFacesContext();
    // Invoke the default ActionListener
    ActionListener listener = context.getApplication().getActionListener();
    if (listener != null) {
      listener.processAction((ActionEvent) event);
    }
  }
}

代码示例来源:origin: org.apache.myfaces.tobago/tobago-jsf-compat

public void processAction(ActionEvent event) throws AbortProcessingException {
 try {
  base.processAction(event);
 } catch (Throwable e) {
  if (e instanceof FacesException) {
  FacesContext facesContext = FacesContext.getCurrentInstance();
  if (e.getCause() != null) {
    FacesMessage facesMessage = new FacesMessage(e.getCause().toString());
    facesContext.addMessage(null, facesMessage);
  Application application = facesContext.getApplication();
  MethodBinding binding = actionSource.getAction();
  NavigationHandler navHandler = application.getNavigationHandler();

代码示例来源:origin: org.primefaces.extensions/primefaces-extensions

@Override
public void broadcast(final FacesEvent event) throws AbortProcessingException {
  for (final FacesListener listener : getFacesListeners(FacesListener.class)) {
    if (event.isAppropriateListener(listener)) {
      event.processListener(listener);
    }
  }
  if (event instanceof ActionEvent) {
    final FacesContext context = getFacesContext();
    // invoke actionListener
    final MethodExpression listener = getActionListenerMethodExpression();
    if (listener != null) {
      listener.invoke(context.getELContext(), getConvertedMethodParameters(context));
    }
    // invoke action
    final ActionListener actionListener = context.getApplication().getActionListener();
    if (actionListener != null) {
      actionListener.processAction((ActionEvent) event);
    }
  }
}

代码示例来源:origin: org.omnifaces/omnifaces

/**
 * Handle the reset input action as follows, only and only if the current request is an ajax request and the
 * {@link PartialViewContext#getRenderIds()} does not return an empty collection nor is the same as
 * {@link PartialViewContext#getExecuteIds()}: find all {@link EditableValueHolder} components based on
 * {@link PartialViewContext#getRenderIds()} and if the component is not covered by
 * {@link PartialViewContext#getExecuteIds()}, then invoke {@link EditableValueHolder#resetValue()} on the
 * component.
 * @throws IllegalArgumentException When one of the client IDs resolved to a <code>null</code> component. This
 * would however indicate a bug in the concrete {@link PartialViewContext} implementation which is been used.
 */
@Override
public void processAction(ActionEvent event) {
  FacesContext context = FacesContext.getCurrentInstance();
  PartialViewContext partialViewContext = context.getPartialViewContext();
  if (partialViewContext.isAjaxRequest()) {
    Collection<String> renderIds = partialViewContext.getRenderIds();
    if (!renderIds.isEmpty() && !partialViewContext.getExecuteIds().containsAll(renderIds)) {
      context.getViewRoot().visitTree(createVisitContext(context, renderIds, VISIT_HINTS), VISIT_CALLBACK);
    }
  }
  if (wrapped != null && event != null) {
    wrapped.processAction(event);
  }
}

代码示例来源:origin: org.apache.shale/shale-view

/**
 * <p>Handle a default action event.</p>
 *
 * @param event The <code>ActionEvent</code> to be handled
 */
public void processAction(ActionEvent event) {
  // FIXME - this is probably not the final answer, but gives
  // us a starting point to deal with application event handlers
  // throwing exceptions in a way consistent with elsewhere
  try {
    original.processAction(event);
  } catch (Exception e) {
    handleException(FacesContext.getCurrentInstance(), e);
  }
}

代码示例来源:origin: javamelody/javamelody

/** {@inheritDoc} */
@Override
public void processAction(ActionEvent event) { // throws FacesException
  // cette méthode est appelée par JSF RI (Mojarra)
  if (DISABLED || !JSF_COUNTER.isDisplayed()) {
    delegateActionListener.processAction(event);
    return;
  }
  boolean systemError = false;
  try {
    final String actionName = getRequestName(event);
    JSF_COUNTER.bindContextIncludingCpu(actionName);
    delegateActionListener.processAction(event);
  } catch (final Error e) {
    // on catche Error pour avoir les erreurs systèmes
    // mais pas Exception qui sont fonctionnelles en général
    systemError = true;
    throw e;
  } finally {
    // on enregistre la requête dans les statistiques
    JSF_COUNTER.addRequestForCurrentContext(systemError);
  }
}

代码示例来源:origin: spring-projects/spring-webflow

public void testProcessActionWithUIRepeat() {
  UIRepeat uiRepeat = new UIRepeat();
  uiRepeat.setValue(this.dataModel);
  UICommand commandButton = new UICommand();
  uiRepeat.getChildren().add(commandButton);
  this.viewToTest.getChildren().add(uiRepeat);
  Method indexMutator = ReflectionUtils.findMethod(UIRepeat.class, "setIndex", FacesContext.class,
      int.class);
  indexMutator.setAccessible(true);
  ReflectionUtils.invokeMethod(indexMutator, uiRepeat, new MockFacesContext(), 1);
  ActionEvent event = new ActionEvent(commandButton);
  this.selectionTrackingListener.processAction(event);
  assertTrue(this.dataModel.isCurrentRowSelected());
  assertSame(this.dataModel.getSelectedRow(), this.dataModel.getRowData());
  assertTrue(this.delegateListener.processedEvent);
  ReflectionUtils.invokeMethod(indexMutator, uiRepeat, new MockFacesContext(), 2);
  assertFalse(this.dataModel.isCurrentRowSelected());
  assertTrue(this.dataModel.getSelectedRow() != this.dataModel.getRowData());
}

代码示例来源:origin: javax/javaee-web-api

if (!context.getResponseComplete() && (context.getViewRoot() == getViewRootOf(event))) {
  ActionListener listener = context.getApplication().getActionListener();
  if (listener != null) {
    boolean hasMoreViewActionEvents = false;
      listener.processAction((ActionEvent) event);
      hasMoreViewActionEvents = !decrementEventCountAndReturnTrueIfZero(context);
    } finally {
      String viewIdBefore = viewRootBefore.getViewId();
      String viewIdAfter = viewRootAfter.getViewId();
      assert(null != viewIdBefore && null != viewIdAfter);
      boolean viewIdsSame = viewIdBefore.equals(viewIdAfter);

代码示例来源:origin: org.richfaces.ui/richfaces-components-ui

public void processAction(ActionEvent event) throws AbortProcessingException {
    ActionListener instance = null;
    FacesContext faces = FacesContext.getCurrentInstance();
    if (faces == null) {
      return;
    }

    if (this.binding != null) {
      instance = (ActionListener) binding.getValue(faces.getELContext());
    }

    if (instance == null && this.type != null) {
      try {
        instance = TagHandlerUtils.loadClass(this.type, ActionListener.class).newInstance();
      } catch (Exception e) {
        throw new AbortProcessingException("Couldn't lazily instantiate ActionListener", e);
      }

      if (this.binding != null) {
        binding.setValue(faces.getELContext(), instance);
      }
    }

    if (instance != null) {
      instance.processAction(event);
    }
  }
}

代码示例来源:origin: spring-projects/spring-webflow

public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
  if (!JsfUtils.isFlowRequest()) {
    this.delegate.processAction(actionEvent);
    return;
  }
  FacesContext context = FacesContext.getCurrentInstance();
  ActionSource2 source = (ActionSource2) actionEvent.getSource();
  String eventId = null;
  if (source.getActionExpression() != null) {
    if (logger.isDebugEnabled()) {
      logger.debug("Invoking action " + source.getActionExpression());
    }
    eventId = (String) source.getActionExpression().invoke(context.getELContext(), null);
  }
  if (StringUtils.hasText(eventId)) {
    if (logger.isDebugEnabled()) {
      logger.debug("Event '" + eventId + "' detected");
    }
    if (source.isImmediate() || validateModel(context, eventId)) {
      context.getExternalContext().getRequestMap().put(JsfView.EVENT_KEY, eventId);
    }
  } else {
    logger.debug("No action event detected");
    context.getExternalContext().getRequestMap().remove(JsfView.EVENT_KEY);
  }
  // tells JSF lifecycle that rendering should now happen and any subsequent phases should be skipped
  // required in the case of this action listener firing immediately (immediate=true) before validation
  context.renderResponse();
}

代码示例来源:origin: org.apache.deltaspike.modules/deltaspike-jsf-module-impl

@Override
  public void processAction(ActionEvent actionEvent)
  {
    if (this.activated)
    {
      ViewConfigDescriptor viewConfigDescriptor = BeanProvider.getContextualReference(ViewConfigResolver.class)
          .getViewConfigDescriptor(FacesContext.getCurrentInstance().getViewRoot().getViewId());

      ViewControllerUtils.executeViewControllerCallback(viewConfigDescriptor, PreViewAction.class);
    }

    this.wrapped.processAction(actionEvent);
  }
}

代码示例来源:origin: eclipse-ee4j/mojarra

/**
 * <p>
 * In addition to to the default {@link UIComponent#broadcast} processing, pass the
 * {@link ActionEvent} being broadcast to the method referenced by <code>actionListener</code>
 * (if any), and to the default {@link ActionListener} registered on the
 * {@link javax.faces.application.Application}.
 * </p>
 *
 * @param event {@link FacesEvent} to be broadcast
 *
 * @throws AbortProcessingException Signal the JavaServer Faces implementation that no further
 *             processing on the current event should be performed
 * @throws IllegalArgumentException if the implementation class of this {@link FacesEvent} is
 *             not supported by this component
 * @throws NullPointerException if <code>event</code> is <code>null</code>
 */
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
  // Perform standard superclass processing (including calling our
  // ActionListeners)
  super.broadcast(event);
  if (event instanceof ActionEvent) {
    FacesContext context = event.getFacesContext();
    // Invoke the default ActionListener
    ActionListener listener = context.getApplication().getActionListener();
    if (listener != null) {
      listener.processAction((ActionEvent) event);
    }
  }
}

代码示例来源:origin: org.apache.myfaces.tobago/tobago-core

FacesELUtils.invokeMethodExpression(FacesContext.getCurrentInstance(), methodExpression, facesEvent);
 final ActionListener defaultActionListener = getFacesContext().getApplication().getActionListener();
 if (defaultActionListener != null) {
  defaultActionListener.processAction(event);
final ValueExpression expression = getValueExpression(Attributes.selectedIndex.getName());
if (expression != null) {
 expression.setValue(getFacesContext().getELContext(), index);
} else {
 setSelectedIndex(index);

代码示例来源:origin: omnifaces/omnifaces

/**
 * Handle the reset input action as follows, only and only if the current request is an ajax request and the
 * {@link PartialViewContext#getRenderIds()} does not return an empty collection nor is the same as
 * {@link PartialViewContext#getExecuteIds()}: find all {@link EditableValueHolder} components based on
 * {@link PartialViewContext#getRenderIds()} and if the component is not covered by
 * {@link PartialViewContext#getExecuteIds()}, then invoke {@link EditableValueHolder#resetValue()} on the
 * component.
 * @throws IllegalArgumentException When one of the client IDs resolved to a <code>null</code> component. This
 * would however indicate a bug in the concrete {@link PartialViewContext} implementation which is been used.
 */
@Override
public void processAction(ActionEvent event) {
  FacesContext context = FacesContext.getCurrentInstance();
  PartialViewContext partialViewContext = context.getPartialViewContext();
  if (partialViewContext.isAjaxRequest()) {
    Collection<String> renderIds = partialViewContext.getRenderIds();
    if (!renderIds.isEmpty() && !partialViewContext.getExecuteIds().containsAll(renderIds)) {
      context.getViewRoot().visitTree(createVisitContext(context, renderIds, VISIT_HINTS), VISIT_CALLBACK);
    }
  }
  if (wrapped != null && event != null) {
    wrapped.processAction(event);
  }
}

代码示例来源:origin: org.glassfish/javax.faces

/**
   * PENDING
   *
   * @param event The {@link javax.faces.event.ActionEvent} that has occurred
   * @throws javax.faces.event.AbortProcessingException
   *          Signal the JavaServer Faces
   *          implementation that no further processing on the current event
   *          should be performed
   */
  @Override
  public void processAction(ActionEvent event) throws AbortProcessingException {           
    ActionListener instance = (ActionListener)
         Util.getListenerInstance(type, binding);
    if (instance != null) {
      instance.processAction(event);
    } else {
      if (logger.isLoggable(Level.WARNING)) {
        logger.log(Level.WARNING,
              "jsf.core.taglib.action_or_valuechange_listener.null_type_binding",
              new Object[] {
              "ActionListener",
              event.getComponent().getClientId(FacesContext.getCurrentInstance())});
      }
    }
  }
}

相关文章