Search in sources :

Example 1 with MethodExpressionActionListener

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

the class MethodExpressionActionListenerTest method testSaveState.

public void testSaveState() {
    methodExpressionActionListener = new MethodExpressionActionListener(methodExpressionOneArg, methodExpressionZeroArg);
    Object[] expectedState = new Object[] { methodExpressionOneArg, methodExpressionZeroArg };
    Assert.assertTrue("Both MethodExpression instances described in the constructor must be saved.", Arrays.deepEquals(expectedState, (Object[]) methodExpressionActionListener.saveState(facesContext)));
}
Also used : MethodExpressionActionListener(jakarta.faces.event.MethodExpressionActionListener)

Example 2 with MethodExpressionActionListener

use of jakarta.faces.event.MethodExpressionActionListener in project faces by jakartaee.

the class BaseActionSourceTestServlet method actionSourceGetSetActListTest.

// ActionSource.{set,get}ActionListener()
public void actionSourceGetSetActListTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    request.setAttribute("actionListener", new ActionListener() {

        public void processAction(ActionEvent event) throws AbortProcessingException {
        // no-op
        }
    });
    FacesContext context = getFacesContext();
    ELContext elcontext = context.getELContext();
    MethodExpression binding = getApplication().getExpressionFactory().createMethodExpression(elcontext, "#{requestScope.actionListener.processAction}", null, new Class[] { ActionEvent.class });
    ActionSource2 source = (ActionSource2) createComponent();
    MethodExpressionActionListener listener = new MethodExpressionActionListener(binding);
    source.addActionListener(listener);
    ActionListener[] result = source.getActionListeners();
    if (result[0] != listener) {
        out.println(JSFTestUtil.FAIL + " getActionListener() failed to return " + "the value set via setActionListener().");
        out.println("Expected: " + binding);
        out.println("Received: " + result);
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ELContext(jakarta.el.ELContext) ActionListener(jakarta.faces.event.ActionListener) MethodExpressionActionListener(jakarta.faces.event.MethodExpressionActionListener) ActionEvent(jakarta.faces.event.ActionEvent) AbortProcessingException(jakarta.faces.event.AbortProcessingException) ActionSource2(jakarta.faces.component.ActionSource2) MethodExpression(jakarta.el.MethodExpression) PrintWriter(java.io.PrintWriter) MethodExpressionActionListener(jakarta.faces.event.MethodExpressionActionListener)

Example 3 with MethodExpressionActionListener

use of jakarta.faces.event.MethodExpressionActionListener in project faces by jakartaee.

the class TestServlet method uiCommandBroadcastInvokeActionListenerTest.

public void uiCommandBroadcastInvokeActionListenerTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // Ensure that for instances of UICommand, that any actionListenerRefs
    // that are associated with this instance are invoked.
    PrintWriter out = response.getWriter();
    UICommand command = (UICommand) createComponent();
    command.setRendererType(null);
    FacesContext context = getFacesContext();
    System.out.println("COMMAND CLASS: " + command.getClass().getName());
    // Defaults to ANY_PHASE
    ActionEvent event = new ActionEvent(command);
    TestActionListener listener = TestActionListener.withID("ALR");
    request.setAttribute("ListRef", listener);
    MethodExpressionActionListener lnr = new MethodExpressionActionListener(getApplication().getExpressionFactory().createMethodExpression(context.getELContext(), "#{ListRef.processAction}", null, new Class[] { ActionEvent.class }));
    command.addActionListener(lnr);
    command.setImmediate(true);
    TestActionListener.trace(null);
    UIViewRoot root = new UIViewRoot();
    root.getChildren().add(command);
    command.queueEvent(event);
    root.processDecodes(context);
    root.processValidators(context);
    root.processApplication(context);
    String traceExpected = "/ALR@APPLY_REQUEST_VALUES";
    String traceReceived = TestActionListener.trace();
    if (!traceExpected.equals(traceReceived)) {
        out.println(JSFTestUtil.FAIL + " Listeners defined via actionListenerRefs" + "not invoked.");
        out.println("Listener trace expected: " + traceExpected);
        out.println("Listener trace received: " + traceReceived);
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ActionEvent(jakarta.faces.event.ActionEvent) UICommand(jakarta.faces.component.UICommand) UIViewRoot(jakarta.faces.component.UIViewRoot) PrintWriter(java.io.PrintWriter) MethodExpressionActionListener(jakarta.faces.event.MethodExpressionActionListener)

Example 4 with MethodExpressionActionListener

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

the class FaceletViewDeclarationLanguage method applyActionListenerMethodExpressionTarget.

private void applyActionListenerMethodExpressionTarget(FacesContext context, FaceletCompositionContext mctx, ELContext elContext, UIComponent topLevelComponent, UIComponent innerComponent, String attributeName, String targetAttributeName, String attributeExpressionString, ValueExpression attributeNameValueExpression, boolean ccAttrMeRedirection) {
    // First try to remove any prevous target if any
    ActionListener o = (ActionListener) mctx.removeMethodExpressionTargeted(innerComponent, targetAttributeName);
    if (o != null) {
        ((ActionSource2) innerComponent).removeActionListener(o);
    }
    // target is ActionSource2
    ActionListener actionListener = null;
    // it properly.
    if (ccAttrMeRedirection) {
        actionListener = new RedirectMethodExpressionValueExpressionActionListener(attributeNameValueExpression);
    } else {
        MethodExpression methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().createMethodExpression(elContext, attributeExpressionString, Void.TYPE, ACTION_LISTENER_SIGNATURE), attributeNameValueExpression);
        MethodExpression methodExpression2 = reWrapMethodExpression(context.getApplication().getExpressionFactory().createMethodExpression(elContext, attributeExpressionString, Void.TYPE, EMPTY_CLASS_ARRAY), attributeNameValueExpression);
        if (mctx.isUsingPSSOnThisView()) {
            actionListener = new PartialMethodExpressionActionListener(methodExpression, methodExpression2);
        } else {
            actionListener = new MethodExpressionActionListener(methodExpression, methodExpression2);
        }
    }
    ((ActionSource2) innerComponent).addActionListener(actionListener);
    mctx.addMethodExpressionTargeted(innerComponent, targetAttributeName, actionListener);
}
Also used : PartialMethodExpressionActionListener(org.apache.myfaces.view.facelets.tag.faces.PartialMethodExpressionActionListener) RedirectMethodExpressionValueExpressionActionListener(org.apache.myfaces.view.facelets.el.RedirectMethodExpressionValueExpressionActionListener) RedirectMethodExpressionValueExpressionActionListener(org.apache.myfaces.view.facelets.el.RedirectMethodExpressionValueExpressionActionListener) PartialMethodExpressionActionListener(org.apache.myfaces.view.facelets.tag.faces.PartialMethodExpressionActionListener) ActionListener(jakarta.faces.event.ActionListener) MethodExpressionActionListener(jakarta.faces.event.MethodExpressionActionListener) ActionSource2(jakarta.faces.component.ActionSource2) LocationMethodExpression(org.apache.myfaces.view.facelets.el.LocationMethodExpression) MethodExpression(jakarta.el.MethodExpression) ValueExpressionMethodExpression(org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression) MethodExpressionMethodExpression(org.apache.myfaces.view.facelets.el.MethodExpressionMethodExpression) PartialMethodExpressionActionListener(org.apache.myfaces.view.facelets.tag.faces.PartialMethodExpressionActionListener) MethodExpressionActionListener(jakarta.faces.event.MethodExpressionActionListener)

Example 5 with MethodExpressionActionListener

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

the class MethodExpressionActionListenerTest method testMethodExpressionActionListenerMethodExpressionMethodExpression.

public void testMethodExpressionActionListenerMethodExpressionMethodExpression() {
    EasyMock.replay(methodExpressionOneArg);
    EasyMock.replay(methodExpressionZeroArg);
    methodExpressionActionListener = new MethodExpressionActionListener(methodExpressionOneArg, methodExpressionZeroArg);
}
Also used : MethodExpressionActionListener(jakarta.faces.event.MethodExpressionActionListener)

Aggregations

MethodExpressionActionListener (jakarta.faces.event.MethodExpressionActionListener)10 MethodExpression (jakarta.el.MethodExpression)3 ActionSource2 (jakarta.faces.component.ActionSource2)3 FacesContext (jakarta.faces.context.FacesContext)2 ActionEvent (jakarta.faces.event.ActionEvent)2 ActionListener (jakarta.faces.event.ActionListener)2 PrintWriter (java.io.PrintWriter)2 ELContext (jakarta.el.ELContext)1 ExpressionFactory (jakarta.el.ExpressionFactory)1 MethodNotFoundException (jakarta.el.MethodNotFoundException)1 ValueExpression (jakarta.el.ValueExpression)1 FacesException (jakarta.faces.FacesException)1 ActionSource (jakarta.faces.component.ActionSource)1 EditableValueHolder (jakarta.faces.component.EditableValueHolder)1 UICommand (jakarta.faces.component.UICommand)1 UIViewRoot (jakarta.faces.component.UIViewRoot)1 ValueHolder (jakarta.faces.component.ValueHolder)1 AbortProcessingException (jakarta.faces.event.AbortProcessingException)1 MethodExpressionValueChangeListener (jakarta.faces.event.MethodExpressionValueChangeListener)1 MethodExpressionValidator (jakarta.faces.validator.MethodExpressionValidator)1