Search in sources :

Example 1 with ValueChangeListener

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

the class ValueChangeListenerHandler 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);
    EditableValueHolder evh = (EditableValueHolder) parent;
    ValueExpression b = null;
    if (this.binding != null) {
        b = this.binding.getValueExpression(faceletContext, ValueChangeListener.class);
    }
    ValueChangeListener listener = new LazyValueChangeListener(this.listenerType, b);
    evh.addValueChangeListener(listener);
}
Also used : ValueChangeListener(jakarta.faces.event.ValueChangeListener) ValueExpression(jakarta.el.ValueExpression) FaceletContext(jakarta.faces.view.facelets.FaceletContext) EditableValueHolder(jakarta.faces.component.EditableValueHolder)

Example 2 with ValueChangeListener

use of jakarta.faces.event.ValueChangeListener 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)

Example 3 with ValueChangeListener

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

the class ValueChangeListenerHandler method applyAttachedObject.

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

Example 4 with ValueChangeListener

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

the class UIComponentBaseAttachedStateTestCase method testAttachedObjectsMap.

public void testAttachedObjectsMap() throws Exception {
    Map<String, ValueChangeListener> returnedAttachedObjects = null, attachedObjects = new HashMap<>();
    ValueChangeListener toAdd = new ValueChangeListenerTestImpl();
    attachedObjects.put("one", toAdd);
    toAdd = new ValueChangeListenerTestImpl();
    attachedObjects.put("two", toAdd);
    toAdd = new ValueChangeListenerTestImpl();
    attachedObjects.put("three", toAdd);
    Object result = UIComponentBase.saveAttachedState(facesContext, attachedObjects);
    returnedAttachedObjects = (Map<String, ValueChangeListener>) UIComponentBase.restoreAttachedState(facesContext, result);
}
Also used : ValueChangeListener(jakarta.faces.event.ValueChangeListener) HashMap(java.util.HashMap)

Example 5 with ValueChangeListener

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

the class UIComponentBaseAttachedStateTestCase method testAttachedObjectsStack.

public void testAttachedObjectsStack() throws Exception {
    Stack<ValueChangeListener> returnedAttachedObjects = null, attachedObjects = new Stack<>();
    ValueChangeListener toAdd = new ValueChangeListenerTestImpl();
    attachedObjects.add(toAdd);
    toAdd = new ValueChangeListenerTestImpl();
    attachedObjects.add(toAdd);
    toAdd = new ValueChangeListenerTestImpl();
    attachedObjects.add(toAdd);
    Object result = UIComponentBase.saveAttachedState(facesContext, attachedObjects);
    returnedAttachedObjects = (Stack<ValueChangeListener>) UIComponentBase.restoreAttachedState(facesContext, result);
}
Also used : ValueChangeListener(jakarta.faces.event.ValueChangeListener) Stack(java.util.Stack)

Aggregations

ValueChangeListener (jakarta.faces.event.ValueChangeListener)8 EditableValueHolder (jakarta.faces.component.EditableValueHolder)4 ValueExpression (jakarta.el.ValueExpression)2 MethodExpressionValueChangeListener (jakarta.faces.event.MethodExpressionValueChangeListener)2 FaceletContext (jakarta.faces.view.facelets.FaceletContext)2 HashSet (java.util.HashSet)2 MethodExpression (jakarta.el.MethodExpression)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Stack (java.util.Stack)1 LocationMethodExpression (org.apache.myfaces.view.facelets.el.LocationMethodExpression)1 MethodExpressionMethodExpression (org.apache.myfaces.view.facelets.el.MethodExpressionMethodExpression)1 RedirectMethodExpressionValueExpressionValueChangeListener (org.apache.myfaces.view.facelets.el.RedirectMethodExpressionValueExpressionValueChangeListener)1 ValueExpressionMethodExpression (org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression)1 PartialMethodExpressionValueChangeListener (org.apache.myfaces.view.facelets.tag.faces.PartialMethodExpressionValueChangeListener)1