Search in sources :

Example 1 with CaptureResultCallback

use of org.apache.tapestry5.internal.util.CaptureResultCallback in project tapestry-5 by apache.

the class AjaxFormUpdateControllerImpl method createInternalFormSupport.

private InternalFormSupport createInternalFormSupport(String formClientId, String formComponentId, ComponentActionSink actionSink) {
    // Kind of ugly, but the only way to ensure we don't have name collisions on the
    // client side is to force a unique id into each name (as well as each id, but that's
    // JavaScriptSupport's job). It would be nice if we could agree on the uid, but
    // not essential.
    String uid = Long.toHexString(System.nanoTime());
    IdAllocator idAllocator = new IdAllocator("_" + uid);
    Component formComponent = componentSource.getComponent(formComponentId);
    CaptureResultCallback<InternalFormSupport> callback = CaptureResultCallback.create();
    // This is a bit of a back-door to access a non-public method!
    formComponent.getComponentResources().triggerEvent("internalCreateRenderTimeFormSupport", new Object[] { formClientId, actionSink, idAllocator }, callback);
    return callback.getResult();
}
Also used : IdAllocator(org.apache.tapestry5.ioc.util.IdAllocator) InternalFormSupport(org.apache.tapestry5.corelib.internal.InternalFormSupport) Component(org.apache.tapestry5.runtime.Component)

Example 2 with CaptureResultCallback

use of org.apache.tapestry5.internal.util.CaptureResultCallback in project tapestry-5 by apache.

the class Select method onChange.

Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException {
    final Object newValue = toValue(selectValue);
    CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>();
    EventContext newContext = new AbstractEventContext() {

        @Override
        public int getCount() {
            return context.getCount() + 1;
        }

        @Override
        public <T> T get(Class<T> desiredType, int index) {
            if (index == 0) {
                return typeCoercer.coerce(newValue, desiredType);
            }
            return context.get(desiredType, index - 1);
        }
    };
    this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback);
    this.value = newValue;
    return callback.getResult();
}
Also used : AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext) CaptureResultCallback(org.apache.tapestry5.internal.util.CaptureResultCallback) AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext)

Example 3 with CaptureResultCallback

use of org.apache.tapestry5.internal.util.CaptureResultCallback in project tapestry-5 by apache.

the class Tree method doUpdateSelected.

Object doUpdateSelected(String nodeId, boolean selected) {
    TreeNode node = model.getById(nodeId);
    String event;
    if (selected) {
        selectionModel.select(node);
        event = EventConstants.NODE_SELECTED;
    } else {
        selectionModel.unselect(node);
        event = EventConstants.NODE_UNSELECTED;
    }
    CaptureResultCallback<Object> callback = CaptureResultCallback.create();
    resources.triggerEvent(event, new Object[] { nodeId }, callback);
    final Object result = callback.getResult();
    if (result != null) {
        return result;
    }
    return new JSONObject();
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) JSONObject(org.apache.tapestry5.json.JSONObject)

Aggregations

InternalFormSupport (org.apache.tapestry5.corelib.internal.InternalFormSupport)1 AbstractEventContext (org.apache.tapestry5.internal.AbstractEventContext)1 CaptureResultCallback (org.apache.tapestry5.internal.util.CaptureResultCallback)1 IdAllocator (org.apache.tapestry5.ioc.util.IdAllocator)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 Component (org.apache.tapestry5.runtime.Component)1