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