Wiki Markup |
---|
{scrollbar} |
Ajax Components
Main article: Ajax and Zones
...
From the event handler method, instead of returning a Block or a Component, return a multi-zone update:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Inject private Block searchResults; @Inject private Block statusBlock; @Inject private AjaxResponseRenderer ajaxResponseRenderer; Objectvoid onSuccessFromSearchForm() { searchHits = searchService.performSearch(query); message = String.format("Found %,d matching documents", searchHits.size()); return new MultiZoneUpdateajaxResponseRenderer.addRender("results", searchResults).addaddRender("status", statusBlock); } |
The above will work in Note: Users of Tapestry 5.3, but MultiZoneUpdate is deprecated. For 5.3 and later, use AjaxResponseRenderer instead:
...
controls | true |
---|---|
language | java |
title | Multiple Zone Update (5.3) |
...
2 and earlier (which didn't support AjaxResponseRenderer) must replace that last line with: return new MultiZoneUpdate("results", searchResults).add("status",
...
statusBlock);
...
AjaxResponseRenderer adds other useful commands as well. It also has the advantage that a simple return value can be returned to render content for the Zone that triggered the request.
...
At the same time, Tapestry wants to position the <input> field in a valid location, and HTML defines some constraints for that; an input field must appear inside a <p> or <div> element. In If your zone is initially empty Zone, there's no place to put the hidden element, and Tapestry will complain.
The solution is to simple: just add a <div> element to the body of the zone; this . This ensures that there's a place for the hidden input field. An empty <div> element (even one containing a hidden form field) will not affect page layout.
Wiki Markup |
---|
{scrollbar} |