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