use of org.apache.tapestry5.corelib.components.Zone in project tapestry-5 by apache.
the class Form method beginRender.
void beginRender(MarkupWriter writer) {
Link link = resources.createFormEventLink(EventConstants.ACTION, context);
String actionURL = secure && secureEnabled ? link.toAbsoluteURI(true) : link.toURI();
actionSink = new ComponentActionSink(logger, clientDataEncoder);
clientId = javascriptSupport.allocateClientId(resources);
// Pre-register some names, to prevent client-side collisions with function names
// attached to the JS Form object.
IdAllocator allocator = new IdAllocator();
preallocateNames(allocator);
formSupport = createRenderTimeFormSupport(clientId, actionSink, allocator);
environment.push(FormSupport.class, formSupport);
environment.push(ValidationTracker.class, tracker);
if (autofocus) {
ValidationDecorator autofocusDecorator = new AutofocusValidationDecorator(environment.peek(ValidationDecorator.class), tracker, javascriptSupport);
environment.push(ValidationDecorator.class, autofocusDecorator);
}
// Now that the environment is setup, inform the component or other
// listeners that the form
// is about to render.
resources.triggerEvent(EventConstants.PREPARE_FOR_RENDER, context, null);
resources.triggerEvent(EventConstants.PREPARE, context, null);
// Push BeanValidationContext only after the container had a chance to prepare
environment.push(BeanValidationContext.class, new BeanValidationContextImpl(validate));
// Save the form element for later, in case we want to write an encoding
// type attribute.
form = writer.element("form", "id", clientId, "method", "post", "action", actionURL, "data-update-zone", zone, DATA_ATTRIBUTE, DATA_ATTRIBUTE_VALUE);
if (clientValidation != ClientValidation.NONE) {
writer.attributes("data-validate", "submit");
}
if (async) {
javascriptSupport.require("t5/core/zone");
writer.attributes("data-async-trigger", true);
}
resources.renderInformalParameters(writer);
div = writer.element("div");
for (String parameterName : link.getParameterNames()) {
String[] values = link.getParameterValues(parameterName);
for (String value : values) {
// but the input value shouldn't be encoded.
try {
value = URLDecoder.decode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("Enable to decode parameter value for parameter {} in form {}", parameterName, form.getName(), e);
}
writer.element("input", "type", "hidden", "name", parameterName, "value", value);
writer.end();
}
}
// div
writer.end();
environment.peek(Heartbeat.class).begin();
}
use of org.apache.tapestry5.corelib.components.Zone in project tapestry-5 by apache.
the class GridPager method writePageLink.
private void writePageLink(MarkupWriter writer, int pageIndex) {
if (pageIndex < 1 || pageIndex > maxPages)
return;
if (pageIndex <= lastIndex)
return;
final boolean isBootstrap4 = isBootstrap4();
if (pageIndex != lastIndex + 1) {
writer.element("li", "class", isBootstrap4 ? "disabled page-item" : "disabled");
writer.element("a", "href", "#", "aria-disabled", "true");
addClassAttributeToPageLinkIfNeeded(writer, isBootstrap4);
writer.write(" ... ");
writer.end();
writer.end();
}
lastIndex = pageIndex;
if (pageIndex == currentPage) {
writer.element("li", "aria-current", "page", "class", isBootstrap4 ? "active page-item" : "active");
writer.element("a", "href", "#", "aria-disabled", "true");
addClassAttributeToPageLinkIfNeeded(writer, isBootstrap4);
writer.write(Integer.toString(pageIndex));
writer.end();
writer.end();
return;
}
writer.element("li");
if (isBootstrap4) {
writer.getElement().attribute("class", "page-item");
}
Link link = resources.createEventLink(EventConstants.ACTION, pageIndex);
if (zone != null) {
link.addParameter("t:inplace", "true");
}
writer.element("a", "href", link, "data-update-zone", zone, "title", messages.format("core-goto-page", pageIndex));
addClassAttributeToPageLinkIfNeeded(writer, isBootstrap4);
writer.write(Integer.toString(pageIndex));
writer.end();
// li
writer.end();
}
use of org.apache.tapestry5.corelib.components.Zone in project tapestry5-hotel-booking by ccordenier.
the class AjaxLoader method initAjaxLoader.
@BeginRender
void initAjaxLoader(MarkupWriter writer) {
loader = javascriptSupport.allocateClientId("loader");
JSONObject data = new JSONObject();
data.put("zone", zone);
data.put("trigger", trigger);
data.put("loader", loader);
javascriptSupport.addInitializerCall(InitializationPriority.NORMAL, "initAjaxLoader", data);
}
use of org.apache.tapestry5.corelib.components.Zone in project tapestry-5 by apache.
the class ZoneRefresh method addJavaScript.
@AfterRender
void addJavaScript() {
Link link = resources.createEventLink("zoneRefresh", context);
javaScriptSupport.require("t5/core/zone-refresh").with(zone.getClientId(), period, link.toString());
}
use of org.apache.tapestry5.corelib.components.Zone in project tapestry-5 by apache.
the class MultiZoneUpdateEventResultProcessor method processResultValue.
public void processResultValue(final MultiZoneUpdate value) throws IOException {
Map<String, Object> map = value.getZoneToRenderMap();
for (String zoneId : map.keySet()) {
Object provided = map.get(zoneId);
// The AjaxResponseRenderer will convert the object to a RenderCommand, but does nothing special if there's a failure
// (because the stack trace will clearly identify what's going on). We do the conversion here so that we can relate
// a failure to a zone id. It will just be a pass-thru on the second type coercion.
RenderCommand zoneRenderCommand = toRenderer(zoneId, provided);
ajaxResponseRenderer.addRender(zoneId, zoneRenderCommand);
}
// This is actually executed deferred:
partialRenderer.renderPartialPageMarkup();
}
Aggregations