use of org.apache.tapestry5.internal.AbstractEventContext 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();
}
use of org.apache.tapestry5.internal.AbstractEventContext in project tapestry-5 by apache.
the class Autocomplete method onAutocomplete.
Object onAutocomplete(final EventContext context, @RequestParameter("t:input") final String input) {
final Holder<List> matchesHolder = Holder.create();
// Default it to an empty list.
matchesHolder.put(Collections.emptyList());
ComponentEventCallback callback = new ComponentEventCallback() {
public boolean handleResult(Object result) {
List matches = coercer.coerce(result, List.class);
matchesHolder.put(matches);
return true;
}
};
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 coercer.coerce(input, desiredType);
}
return context.get(desiredType, index - 1);
}
};
resources.triggerContextEvent(EventConstants.PROVIDE_COMPLETIONS, newContext, callback);
JSONObject reply = new JSONObject();
reply.put("matches", JSONArray.from(matchesHolder.get()));
// A JSONObject response is always preferred, as that triggers the whole partial page render pipeline.
return reply;
}
Aggregations