Search in sources :

Example 1 with ActionListener

use of jakarta.faces.event.ActionListener in project myfaces by apache.

the class UIViewAction method broadcast.

@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
    super.broadcast(event);
    FacesContext context = getFacesContext();
    if (context.getResponseComplete()) {
        return;
    }
    UIComponent c = event.getComponent();
    UIViewRoot sourceViewRoot = null;
    do {
        if (c instanceof UIViewRoot) {
            sourceViewRoot = (UIViewRoot) c;
            break;
        } else {
            c = c.getParent();
        }
    } while (c != null);
    if (!context.getViewRoot().equals(sourceViewRoot)) {
        return;
    }
    if (event instanceof ActionEvent) {
        ActionListener defaultActionListener = context.getApplication().getActionListener();
        if (defaultActionListener != null) {
            String viewIdBeforeAction = context.getViewRoot().getViewId();
            Boolean oldBroadcastProcessing = (Boolean) context.getAttributes().get(BROADCAST_PROCESSING_KEY);
            try {
                context.getAttributes().put(BROADCAST_PROCESSING_KEY, Boolean.TRUE);
                ViewActionFacesContextWrapper wrappedFacesContext = new ViewActionFacesContextWrapper(context);
                try {
                    wrappedFacesContext.setWrapperAsCurrentFacesContext();
                    if (event instanceof ViewActionEvent) {
                        ((ViewActionEvent) event).setFacesContext(wrappedFacesContext);
                    }
                    defaultActionListener.processAction((ActionEvent) event);
                    // Decrement count
                    Integer count = (Integer) context.getAttributes().get(EVENT_COUNT_KEY);
                    count = (count == null) ? 0 : count - 1;
                    context.getAttributes().put(EVENT_COUNT_KEY, count);
                } finally {
                    wrappedFacesContext.restoreCurrentFacesContext();
                }
            } finally {
                context.getAttributes().put(BROADCAST_PROCESSING_KEY, oldBroadcastProcessing == null ? Boolean.FALSE : oldBroadcastProcessing);
            }
            if (context.getResponseComplete()) {
                return;
            } else {
                Integer count = (Integer) context.getAttributes().get(EVENT_COUNT_KEY);
                count = (count == null) ? 0 : count;
                String viewIdAfterAction = context.getViewRoot().getViewId();
                if (viewIdBeforeAction.equals(viewIdAfterAction) && count == 0) {
                    context.renderResponse();
                }
            // "... Otherwise, execute the lifecycle on the new UIViewRoot ..."
            // Note these words are implemented in the NavigationHandler, but
            // the original proposal from seam s:viewAction did a trick here
            // to restart the JSF lifecycle.
            }
        }
    }
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ActionListener(jakarta.faces.event.ActionListener) ActionEvent(jakarta.faces.event.ActionEvent)

Example 2 with ActionListener

use of jakarta.faces.event.ActionListener in project myfaces by apache.

the class UICommand method broadcast.

@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
    super.broadcast(event);
    if (event instanceof ActionEvent) {
        FacesContext context = getFacesContext();
        ActionListener defaultActionListener = context.getApplication().getActionListener();
        if (defaultActionListener != null) {
            defaultActionListener.processAction((ActionEvent) event);
        }
    }
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ActionListener(jakarta.faces.event.ActionListener) ActionEvent(jakarta.faces.event.ActionEvent)

Example 3 with ActionListener

use of jakarta.faces.event.ActionListener in project myfaces by apache.

the class ActionListenerHandler method applyAttachedObject.

@Override
public void applyAttachedObject(FacesContext context, UIComponent parent) {
    // Retrieve the current FaceletContext from FacesContext object
    FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
    ActionSource as = (ActionSource) parent;
    ValueExpression b = null;
    if (this.binding != null) {
        b = this.binding.getValueExpression(faceletContext, ActionListener.class);
    }
    ActionListener listener = new LazyActionListener(this.listenerType, b);
    as.addActionListener(listener);
}
Also used : ActionListener(jakarta.faces.event.ActionListener) ValueExpression(jakarta.el.ValueExpression) FaceletContext(jakarta.faces.view.facelets.FaceletContext) ActionSource(jakarta.faces.component.ActionSource)

Example 4 with ActionListener

use of jakarta.faces.event.ActionListener in project mojarra by eclipse-ee4j.

the class ActionListenerHandler method applyAttachedObject.

@Override
public void applyAttachedObject(FacesContext context, UIComponent parent) {
    FaceletContext ctx = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
    ActionSource as = (ActionSource) parent;
    ValueExpression b = null;
    if (binding != null) {
        b = binding.getValueExpression(ctx, ActionListener.class);
    }
    ActionListener listener = new LazyActionListener(listenerType, b);
    as.addActionListener(listener);
}
Also used : ActionListener(jakarta.faces.event.ActionListener) ValueExpression(jakarta.el.ValueExpression) FaceletContext(jakarta.faces.view.facelets.FaceletContext) ActionSource(jakarta.faces.component.ActionSource)

Example 5 with ActionListener

use of jakarta.faces.event.ActionListener in project mojarra by eclipse-ee4j.

the class ResetValuesHandler method applyAttachedObject.

@Override
public void applyAttachedObject(FacesContext context, UIComponent parent) {
    FaceletContext ctx = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
    ActionSource as = (ActionSource) parent;
    String renderStr = (String) render.getObject(ctx, String.class);
    ActionListener listener = new LazyActionListener(toList(renderStr));
    as.addActionListener(listener);
}
Also used : ActionListener(jakarta.faces.event.ActionListener) FaceletContext(jakarta.faces.view.facelets.FaceletContext) ActionSource(jakarta.faces.component.ActionSource)

Aggregations

ActionListener (jakarta.faces.event.ActionListener)21 ActionEvent (jakarta.faces.event.ActionEvent)6 PrintWriter (java.io.PrintWriter)6 FacesContext (jakarta.faces.context.FacesContext)5 TCKActionListener (com.sun.ts.tests.jsf.common.listener.TCKActionListener)4 ActionSource (jakarta.faces.component.ActionSource)4 FaceletContext (jakarta.faces.view.facelets.FaceletContext)4 MethodExpression (jakarta.el.MethodExpression)3 ValueExpression (jakarta.el.ValueExpression)3 Application (jakarta.faces.application.Application)3 ActionSource2 (jakarta.faces.component.ActionSource2)3 MethodExpressionActionListener (jakarta.faces.event.MethodExpressionActionListener)3 IOException (java.io.IOException)3 ELException (jakarta.el.ELException)2 FacesException (jakarta.faces.FacesException)2 ApplicationWrapper (jakarta.faces.application.ApplicationWrapper)2 UICommand (jakarta.faces.component.UICommand)2 ServletException (jakarta.servlet.ServletException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2