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

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

本文整理了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

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

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

  1. if (context.getResponseComplete())
  2. if (!context.getViewRoot().equals(sourceViewRoot))
  3. ActionListener defaultActionListener = context.getApplication().getActionListener();
  4. if (defaultActionListener != null)
  5. String viewIdBeforeAction = context.getViewRoot().getViewId();
  6. Boolean oldBroadcastProcessing = (Boolean) context.getAttributes().
  7. get(BROADCAST_PROCESSING_KEY);
  8. defaultActionListener.processAction((ActionEvent) event);
  9. Integer count = (Integer) context.getAttributes().get(EVENT_COUNT_KEY);
  10. count = (count == null) ? 0 : count;
  11. String viewIdAfterAction = context.getViewRoot().getViewId();

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

  1. public void processAction(ActionEvent event) throws AbortProcessingException {
  2. ActionListener instance = null;
  3. FacesContext faces = FacesContext.getCurrentInstance();
  4. if (faces == null) {
  5. return;
  6. }
  7. if (this.binding != null) {
  8. instance = (ActionListener) binding.getValue(faces.getELContext());
  9. }
  10. if (instance == null && this.type != null) {
  11. try {
  12. instance = TagHandlerUtils.loadClass(this.type, ActionListener.class).newInstance();
  13. } catch (Exception e) {
  14. throw new AbortProcessingException("Couldn't lazily instantiate ActionListener", e);
  15. }
  16. if (this.binding != null) {
  17. binding.setValue(faces.getELContext(), instance);
  18. }
  19. }
  20. if (instance != null) {
  21. instance.processAction(event);
  22. }
  23. }
  24. }

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

  1. public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
  2. if (!JsfUtils.isFlowRequest()) {
  3. delegate.processAction(actionEvent);
  4. return;
  5. }
  6. FacesContext context = FacesContext.getCurrentInstance();
  7. ActionSource source = (ActionSource) actionEvent.getSource();
  8. String eventId = null;
  9. if (source.getAction() != null) {
  10. if (logger.isDebugEnabled()) {
  11. logger.debug("Invoking action " + source.getAction());
  12. }
  13. eventId = (String) source.getAction().invoke(context, null);
  14. }
  15. if (StringUtils.hasText(eventId)) {
  16. if (logger.isDebugEnabled()) {
  17. logger.debug("Event '" + eventId + "' detected");
  18. }
  19. if (source.isImmediate() || validateModel(context, eventId)) {
  20. context.getExternalContext().getRequestMap().put(JsfView.EVENT_KEY, eventId);
  21. }
  22. } else {
  23. logger.debug("No action event detected");
  24. context.getExternalContext().getRequestMap().remove(JsfView.EVENT_KEY);
  25. }
  26. // tells JSF lifecycle that rendering should now happen and any subsequent phases should be skipped
  27. // required in the case of this action listener firing immediately (immediate=true) before validation
  28. context.renderResponse();
  29. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public void processAction(ActionEvent actionEvent)
  5. {
  6. if(this.deactivated)
  7. {
  8. return;
  9. }
  10. ViewConfigDescriptor viewConfigDescriptor =
  11. ViewConfigCache.getViewConfigDescriptor(FacesContext.getCurrentInstance().getViewRoot().getViewId());
  12. if(viewConfigDescriptor instanceof EditableViewConfigDescriptor)
  13. {
  14. ((EditableViewConfigDescriptor)viewConfigDescriptor).invokePrePageActionMethods();
  15. }
  16. this.wrapped.processAction(actionEvent);
  17. }

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

  1. /**
  2. * <p>
  3. * In addition to to the default {@link UIComponent#broadcast} processing, pass the
  4. * {@link ActionEvent} being broadcast to the method referenced by <code>actionListener</code>
  5. * (if any), and to the default {@link ActionListener} registered on the
  6. * {@link javax.faces.application.Application}.
  7. * </p>
  8. *
  9. * @param event {@link FacesEvent} to be broadcast
  10. *
  11. * @throws AbortProcessingException Signal the JavaServer Faces implementation that no further
  12. * processing on the current event should be performed
  13. * @throws IllegalArgumentException if the implementation class of this {@link FacesEvent} is
  14. * not supported by this component
  15. * @throws NullPointerException if <code>event</code> is <code>null</code>
  16. */
  17. @Override
  18. public void broadcast(FacesEvent event) throws AbortProcessingException {
  19. // Perform standard superclass processing (including calling our
  20. // ActionListeners)
  21. super.broadcast(event);
  22. if (event instanceof ActionEvent) {
  23. FacesContext context = event.getFacesContext();
  24. // Invoke the default ActionListener
  25. ActionListener listener = context.getApplication().getActionListener();
  26. if (listener != null) {
  27. listener.processAction((ActionEvent) event);
  28. }
  29. }
  30. }

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

  1. public void processAction(ActionEvent event) throws AbortProcessingException {
  2. try {
  3. base.processAction(event);
  4. } catch (Throwable e) {
  5. if (e instanceof FacesException) {
  6. FacesContext facesContext = FacesContext.getCurrentInstance();
  7. if (e.getCause() != null) {
  8. FacesMessage facesMessage = new FacesMessage(e.getCause().toString());
  9. facesContext.addMessage(null, facesMessage);
  10. Application application = facesContext.getApplication();
  11. MethodBinding binding = actionSource.getAction();
  12. NavigationHandler navHandler = application.getNavigationHandler();

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

  1. @Override
  2. public void broadcast(final FacesEvent event) throws AbortProcessingException {
  3. for (final FacesListener listener : getFacesListeners(FacesListener.class)) {
  4. if (event.isAppropriateListener(listener)) {
  5. event.processListener(listener);
  6. }
  7. }
  8. if (event instanceof ActionEvent) {
  9. final FacesContext context = getFacesContext();
  10. // invoke actionListener
  11. final MethodExpression listener = getActionListenerMethodExpression();
  12. if (listener != null) {
  13. listener.invoke(context.getELContext(), getConvertedMethodParameters(context));
  14. }
  15. // invoke action
  16. final ActionListener actionListener = context.getApplication().getActionListener();
  17. if (actionListener != null) {
  18. actionListener.processAction((ActionEvent) event);
  19. }
  20. }
  21. }

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

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

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

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

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

  1. /** {@inheritDoc} */
  2. @Override
  3. public void processAction(ActionEvent event) { // throws FacesException
  4. // cette méthode est appelée par JSF RI (Mojarra)
  5. if (DISABLED || !JSF_COUNTER.isDisplayed()) {
  6. delegateActionListener.processAction(event);
  7. return;
  8. }
  9. boolean systemError = false;
  10. try {
  11. final String actionName = getRequestName(event);
  12. JSF_COUNTER.bindContextIncludingCpu(actionName);
  13. delegateActionListener.processAction(event);
  14. } catch (final Error e) {
  15. // on catche Error pour avoir les erreurs systèmes
  16. // mais pas Exception qui sont fonctionnelles en général
  17. systemError = true;
  18. throw e;
  19. } finally {
  20. // on enregistre la requête dans les statistiques
  21. JSF_COUNTER.addRequestForCurrentContext(systemError);
  22. }
  23. }

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

  1. public void testProcessActionWithUIRepeat() {
  2. UIRepeat uiRepeat = new UIRepeat();
  3. uiRepeat.setValue(this.dataModel);
  4. UICommand commandButton = new UICommand();
  5. uiRepeat.getChildren().add(commandButton);
  6. this.viewToTest.getChildren().add(uiRepeat);
  7. Method indexMutator = ReflectionUtils.findMethod(UIRepeat.class, "setIndex", FacesContext.class,
  8. int.class);
  9. indexMutator.setAccessible(true);
  10. ReflectionUtils.invokeMethod(indexMutator, uiRepeat, new MockFacesContext(), 1);
  11. ActionEvent event = new ActionEvent(commandButton);
  12. this.selectionTrackingListener.processAction(event);
  13. assertTrue(this.dataModel.isCurrentRowSelected());
  14. assertSame(this.dataModel.getSelectedRow(), this.dataModel.getRowData());
  15. assertTrue(this.delegateListener.processedEvent);
  16. ReflectionUtils.invokeMethod(indexMutator, uiRepeat, new MockFacesContext(), 2);
  17. assertFalse(this.dataModel.isCurrentRowSelected());
  18. assertTrue(this.dataModel.getSelectedRow() != this.dataModel.getRowData());
  19. }

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

  1. if (!context.getResponseComplete() && (context.getViewRoot() == getViewRootOf(event))) {
  2. ActionListener listener = context.getApplication().getActionListener();
  3. if (listener != null) {
  4. boolean hasMoreViewActionEvents = false;
  5. listener.processAction((ActionEvent) event);
  6. hasMoreViewActionEvents = !decrementEventCountAndReturnTrueIfZero(context);
  7. } finally {
  8. String viewIdBefore = viewRootBefore.getViewId();
  9. String viewIdAfter = viewRootAfter.getViewId();
  10. assert(null != viewIdBefore && null != viewIdAfter);
  11. boolean viewIdsSame = viewIdBefore.equals(viewIdAfter);

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

  1. public void processAction(ActionEvent event) throws AbortProcessingException {
  2. ActionListener instance = null;
  3. FacesContext faces = FacesContext.getCurrentInstance();
  4. if (faces == null) {
  5. return;
  6. }
  7. if (this.binding != null) {
  8. instance = (ActionListener) binding.getValue(faces.getELContext());
  9. }
  10. if (instance == null && this.type != null) {
  11. try {
  12. instance = TagHandlerUtils.loadClass(this.type, ActionListener.class).newInstance();
  13. } catch (Exception e) {
  14. throw new AbortProcessingException("Couldn't lazily instantiate ActionListener", e);
  15. }
  16. if (this.binding != null) {
  17. binding.setValue(faces.getELContext(), instance);
  18. }
  19. }
  20. if (instance != null) {
  21. instance.processAction(event);
  22. }
  23. }
  24. }

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

  1. public void processAction(ActionEvent actionEvent) throws AbortProcessingException {
  2. if (!JsfUtils.isFlowRequest()) {
  3. this.delegate.processAction(actionEvent);
  4. return;
  5. }
  6. FacesContext context = FacesContext.getCurrentInstance();
  7. ActionSource2 source = (ActionSource2) actionEvent.getSource();
  8. String eventId = null;
  9. if (source.getActionExpression() != null) {
  10. if (logger.isDebugEnabled()) {
  11. logger.debug("Invoking action " + source.getActionExpression());
  12. }
  13. eventId = (String) source.getActionExpression().invoke(context.getELContext(), null);
  14. }
  15. if (StringUtils.hasText(eventId)) {
  16. if (logger.isDebugEnabled()) {
  17. logger.debug("Event '" + eventId + "' detected");
  18. }
  19. if (source.isImmediate() || validateModel(context, eventId)) {
  20. context.getExternalContext().getRequestMap().put(JsfView.EVENT_KEY, eventId);
  21. }
  22. } else {
  23. logger.debug("No action event detected");
  24. context.getExternalContext().getRequestMap().remove(JsfView.EVENT_KEY);
  25. }
  26. // tells JSF lifecycle that rendering should now happen and any subsequent phases should be skipped
  27. // required in the case of this action listener firing immediately (immediate=true) before validation
  28. context.renderResponse();
  29. }

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

  1. @Override
  2. public void processAction(ActionEvent actionEvent)
  3. {
  4. if (this.activated)
  5. {
  6. ViewConfigDescriptor viewConfigDescriptor = BeanProvider.getContextualReference(ViewConfigResolver.class)
  7. .getViewConfigDescriptor(FacesContext.getCurrentInstance().getViewRoot().getViewId());
  8. ViewControllerUtils.executeViewControllerCallback(viewConfigDescriptor, PreViewAction.class);
  9. }
  10. this.wrapped.processAction(actionEvent);
  11. }
  12. }

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

  1. /**
  2. * <p>
  3. * In addition to to the default {@link UIComponent#broadcast} processing, pass the
  4. * {@link ActionEvent} being broadcast to the method referenced by <code>actionListener</code>
  5. * (if any), and to the default {@link ActionListener} registered on the
  6. * {@link javax.faces.application.Application}.
  7. * </p>
  8. *
  9. * @param event {@link FacesEvent} to be broadcast
  10. *
  11. * @throws AbortProcessingException Signal the JavaServer Faces implementation that no further
  12. * processing on the current event should be performed
  13. * @throws IllegalArgumentException if the implementation class of this {@link FacesEvent} is
  14. * not supported by this component
  15. * @throws NullPointerException if <code>event</code> is <code>null</code>
  16. */
  17. @Override
  18. public void broadcast(FacesEvent event) throws AbortProcessingException {
  19. // Perform standard superclass processing (including calling our
  20. // ActionListeners)
  21. super.broadcast(event);
  22. if (event instanceof ActionEvent) {
  23. FacesContext context = event.getFacesContext();
  24. // Invoke the default ActionListener
  25. ActionListener listener = context.getApplication().getActionListener();
  26. if (listener != null) {
  27. listener.processAction((ActionEvent) event);
  28. }
  29. }
  30. }

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

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

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

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

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

  1. /**
  2. * PENDING
  3. *
  4. * @param event The {@link javax.faces.event.ActionEvent} that has occurred
  5. * @throws javax.faces.event.AbortProcessingException
  6. * Signal the JavaServer Faces
  7. * implementation that no further processing on the current event
  8. * should be performed
  9. */
  10. @Override
  11. public void processAction(ActionEvent event) throws AbortProcessingException {
  12. ActionListener instance = (ActionListener)
  13. Util.getListenerInstance(type, binding);
  14. if (instance != null) {
  15. instance.processAction(event);
  16. } else {
  17. if (logger.isLoggable(Level.WARNING)) {
  18. logger.log(Level.WARNING,
  19. "jsf.core.taglib.action_or_valuechange_listener.null_type_binding",
  20. new Object[] {
  21. "ActionListener",
  22. event.getComponent().getClientId(FacesContext.getCurrentInstance())});
  23. }
  24. }
  25. }
  26. }

相关文章

ActionListener类方法