Search in sources :

Example 1 with MethodExpressionValueChangeListener

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

the class MethodExpressionValueChangeListenerTest method testMethodExpressionValueChangeListenerMethodExpression.

public void testMethodExpressionValueChangeListenerMethodExpression() {
    EasyMock.replay(methodExpressionOneArg);
    methodExpressionValueChangeListener = new MethodExpressionValueChangeListener(methodExpressionOneArg);
}
Also used : MethodExpressionValueChangeListener(jakarta.faces.event.MethodExpressionValueChangeListener)

Example 2 with MethodExpressionValueChangeListener

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

the class MethodExpressionValueChangeListenerTest method testSaveState.

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

Example 3 with MethodExpressionValueChangeListener

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

the class MethodExpressionValueChangeListenerTest method testProcessValueChange2.

/**
 * Test for case: method exists but has no ValueChangeEvent param (new possibility in JSF 2.0)
 */
public void testProcessValueChange2() throws Exception {
    // First, try to invoke the MethodExpression passed to the constructor of this instance,
    // passing the argument ValueChangeEvent as the argument
    methodExpressionOneArg.invoke(EasyMock.eq(facesContext.getELContext()), EasyMock.aryEq(paramsWithValueChangeEvent));
    EasyMock.expectLastCall().andThrow(new MethodNotFoundException()).times(1);
    // If a MethodNotFoundException  is thrown,
    // call to the zero argument MethodExpression derived from the MethodExpression passed
    // to the constructor of this instance
    methodExpressionZeroArg.invoke(EasyMock.eq(facesContext.getELContext()), EasyMock.aryEq(new Object[0]));
    EasyMock.expectLastCall().andReturn(null).times(1);
    EasyMock.replay(methodExpressionOneArg);
    EasyMock.replay(methodExpressionZeroArg);
    methodExpressionValueChangeListener = new MethodExpressionValueChangeListener(methodExpressionOneArg, methodExpressionZeroArg);
    methodExpressionValueChangeListener.processValueChange(valueChangeEvent);
    EasyMock.verify(methodExpressionOneArg);
    EasyMock.verify(methodExpressionZeroArg);
}
Also used : MethodExpressionValueChangeListener(jakarta.faces.event.MethodExpressionValueChangeListener) MethodNotFoundException(jakarta.el.MethodNotFoundException)

Example 4 with MethodExpressionValueChangeListener

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

the class MethodExpressionValueChangeListenerTest method testProcessValueChange.

/**
 * Test for case: method with ValueChangeEvent param exists (pre-JSF 2.0 case)
 */
public void testProcessValueChange() {
    // First, try to invoke the MethodExpression passed to the constructor of this instance,
    // passing the argument ValueChangeEvent as the argument:
    methodExpressionOneArg.invoke(EasyMock.eq(facesContext.getELContext()), EasyMock.aryEq(paramsWithValueChangeEvent));
    EasyMock.expectLastCall().andReturn(null).times(1);
    EasyMock.replay(methodExpressionOneArg);
    methodExpressionValueChangeListener = new MethodExpressionValueChangeListener(methodExpressionOneArg);
    methodExpressionValueChangeListener.processValueChange(valueChangeEvent);
    EasyMock.verify(methodExpressionOneArg);
}
Also used : MethodExpressionValueChangeListener(jakarta.faces.event.MethodExpressionValueChangeListener)

Example 5 with MethodExpressionValueChangeListener

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

the class FaceletViewDeclarationLanguage method applyValueChangeListenerMethodExpressionTarget.

private void applyValueChangeListenerMethodExpressionTarget(FacesContext context, FaceletCompositionContext mctx, ELContext elContext, UIComponent topLevelComponent, UIComponent innerComponent, String attributeName, String targetAttributeName, String attributeExpressionString, ValueExpression attributeNameValueExpression, boolean ccAttrMeRedirection) {
    ValueChangeListener o = (ValueChangeListener) mctx.removeMethodExpressionTargeted(innerComponent, targetAttributeName);
    if (o != null) {
        ((EditableValueHolder) innerComponent).removeValueChangeListener(o);
    }
    // target is EditableValueHolder
    ValueChangeListener valueChangeListener = null;
    // If it is a redirection, a wrapper is used to locate the right instance and call it properly.
    if (ccAttrMeRedirection) {
        valueChangeListener = new RedirectMethodExpressionValueExpressionValueChangeListener(attributeNameValueExpression);
    } else {
        MethodExpression methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().createMethodExpression(elContext, attributeExpressionString, Void.TYPE, VALUE_CHANGE_LISTENER_SIGNATURE), attributeNameValueExpression);
        MethodExpression methodExpression2 = reWrapMethodExpression(context.getApplication().getExpressionFactory().createMethodExpression(elContext, attributeExpressionString, Void.TYPE, EMPTY_CLASS_ARRAY), attributeNameValueExpression);
        if (mctx.isUsingPSSOnThisView()) {
            valueChangeListener = new PartialMethodExpressionValueChangeListener(methodExpression, methodExpression2);
        } else {
            valueChangeListener = new MethodExpressionValueChangeListener(methodExpression, methodExpression2);
        }
    }
    ((EditableValueHolder) innerComponent).addValueChangeListener(valueChangeListener);
    mctx.addMethodExpressionTargeted(innerComponent, targetAttributeName, valueChangeListener);
}
Also used : PartialMethodExpressionValueChangeListener(org.apache.myfaces.view.facelets.tag.faces.PartialMethodExpressionValueChangeListener) ValueChangeListener(jakarta.faces.event.ValueChangeListener) PartialMethodExpressionValueChangeListener(org.apache.myfaces.view.facelets.tag.faces.PartialMethodExpressionValueChangeListener) MethodExpressionValueChangeListener(jakarta.faces.event.MethodExpressionValueChangeListener) RedirectMethodExpressionValueExpressionValueChangeListener(org.apache.myfaces.view.facelets.el.RedirectMethodExpressionValueExpressionValueChangeListener) PartialMethodExpressionValueChangeListener(org.apache.myfaces.view.facelets.tag.faces.PartialMethodExpressionValueChangeListener) MethodExpressionValueChangeListener(jakarta.faces.event.MethodExpressionValueChangeListener) RedirectMethodExpressionValueExpressionValueChangeListener(org.apache.myfaces.view.facelets.el.RedirectMethodExpressionValueExpressionValueChangeListener) 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) EditableValueHolder(jakarta.faces.component.EditableValueHolder)

Aggregations

MethodExpressionValueChangeListener (jakarta.faces.event.MethodExpressionValueChangeListener)14 MethodExpression (jakarta.el.MethodExpression)8 PrintWriter (java.io.PrintWriter)6 FacesContext (jakarta.faces.context.FacesContext)5 TCKValueChangeListener (com.sun.ts.tests.jsf.api.jakarta_faces.component.common.TCKValueChangeListener)4 UIInput (jakarta.faces.component.UIInput)4 UIViewRoot (jakarta.faces.component.UIViewRoot)4 ValueChangeEvent (jakarta.faces.event.ValueChangeEvent)4 EditableValueHolder (jakarta.faces.component.EditableValueHolder)3 ELContext (jakarta.el.ELContext)2 ExpressionFactory (jakarta.el.ExpressionFactory)2 MethodNotFoundException (jakarta.el.MethodNotFoundException)1 ValueExpression (jakarta.el.ValueExpression)1 FacesException (jakarta.faces.FacesException)1 ActionSource (jakarta.faces.component.ActionSource)1 ActionSource2 (jakarta.faces.component.ActionSource2)1 ValueHolder (jakarta.faces.component.ValueHolder)1 MethodExpressionActionListener (jakarta.faces.event.MethodExpressionActionListener)1 ValueChangeListener (jakarta.faces.event.ValueChangeListener)1 MethodExpressionValidator (jakarta.faces.validator.MethodExpressionValidator)1