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)));
}
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);
}
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);
}
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);
}
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);
}
Aggregations