Search in sources :

Example 16 with Event

use of org.apache.tapestry5.runtime.Event in project tapestry-5 by apache.

the class LinkSubmit method processSubmission.

private void processSubmission(String clientId) {
    this.clientId = clientId;
    String raw = request.getParameter(Form.SUBMITTING_ELEMENT_ID);
    if (InternalUtils.isNonBlank(raw) && new JSONArray(raw).getString(0).equals(clientId)) {
        Runnable notification = new Runnable() {

            public void run() {
                resources.triggerEvent(event, context, eventCallback);
            }
        };
        if (defer)
            formSupport.defer(notification);
        else
            heartbeat.defer(notification);
    }
}
Also used : JSONArray(org.apache.tapestry5.json.JSONArray)

Example 17 with Event

use of org.apache.tapestry5.runtime.Event in project tapestry-5 by apache.

the class PublishServerSideEvents method addEventsAttribute.

private void addEventsAttribute(final Element element) {
    if (element == null) {
        throw new IllegalStateException("@PublishEvent used inside a page which didn't generate a <body> element");
    }
    final ComponentResources containerResources = resources.getContainerResources();
    final ComponentModel componentModel = containerResources.getComponentModel();
    final String metaValue = componentModel.getMeta(InternalConstants.PUBLISH_COMPONENT_EVENTS_META);
    final JSONArray componentEvents = new JSONArray(metaValue);
    final JSONObject events = new JSONObject();
    final String existingValue = element.getAttribute(COMPONENT_EVENTS_ATTRIBUTE_NAME);
    if (existingValue != null) {
        final JSONObject existing = new JSONObject(existingValue);
        for (String key : existing.keys()) {
            events.put(key, existing.get(key));
        }
    }
    for (int i = 0; i < componentEvents.length(); i++) {
        final String eventName = componentEvents.getString(i);
        JSONObject event = new JSONObject();
        event.put(PUBLISH_COMPONENT_EVENTS_URL_PROPERTY, containerResources.createEventLink(eventName).toString());
        events.put(eventName, event);
    }
    element.forceAttributes(TapestryConstants.COMPONENT_EVENTS_ATTRIBUTE_NAME, events.toString());
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) ComponentModel(org.apache.tapestry5.model.ComponentModel) JSONArray(org.apache.tapestry5.json.JSONArray) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 18 with Event

use of org.apache.tapestry5.runtime.Event 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)

Example 19 with Event

use of org.apache.tapestry5.runtime.Event in project tapestry-5 by apache.

the class FormInjectorDemo method onAddRow.

Object onAddRow(long context) {
    Assert.assertEquals(context, DEMO_CONTEXT_VALUE, "Context value provided to AjaxFormLoop must be provided to the event handler method.");
    DoubleItem item = new DoubleItem();
    item.setId(ID_ALLOCATOR.incrementAndGet());
    database.put(item.getId(), item);
    return item;
}
Also used : DoubleItem(org.apache.tapestry5.integration.app1.data.DoubleItem)

Example 20 with Event

use of org.apache.tapestry5.runtime.Event in project tapestry-5 by apache.

the class ComponentEventImplTest method no_match_one_event_is_aborted.

/**
 * @since 5.2.0
 */
@Test
public void no_match_one_event_is_aborted() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    Object result = new Object();
    ComponentPageElementResources resources = mockResources();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_handleResult(handler, result, true);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger);
    event.storeResult(result);
    assertFalse(event.matches("eventType", "someId", 0));
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentPageElementResources(org.apache.tapestry5.internal.structure.ComponentPageElementResources) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Aggregations

ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)19 ComponentModel (org.apache.tapestry5.model.ComponentModel)14 Logger (org.slf4j.Logger)14 Test (org.testng.annotations.Test)14 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)13 JSONObject (org.apache.tapestry5.json.JSONObject)11 EventContext (org.apache.tapestry5.EventContext)9 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)6 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)6 Component (org.apache.tapestry5.runtime.Component)6 ComponentResources (org.apache.tapestry5.ComponentResources)4 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)4 JSONArray (org.apache.tapestry5.json.JSONArray)4 ComponentEventHandler (org.apache.tapestry5.services.ComponentEventHandler)4 TrackableComponentEventCallback (org.apache.tapestry5.TrackableComponentEventCallback)3 ComponentPageElement (org.apache.tapestry5.internal.structure.ComponentPageElement)3 Page (org.apache.tapestry5.internal.structure.Page)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Link (org.apache.tapestry5.Link)2