You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by "Howard M. Lewis Ship (JIRA)" <ji...@apache.org> on 2011/01/07 18:51:49 UTC
[jira] Commented: (TAP5-1407) multizoneupdate should be easier to
use - not a chain
[ https://issues.apache.org/jira/browse/TAP5-1407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12978883#action_12978883 ]
Howard M. Lewis Ship commented on TAP5-1407:
--------------------------------------------
Actually, I'm thinking the MultiZoneUpdate object could be deprecated, and a service take its place. MZU is just a bit unwieldy to use, despite some work on it in 5.2 and, in the long run, it doesn't actually prevent some amount of per-thread state from being stored ... in other words, over-engineered.
> multizoneupdate should be easier to use - not a chain
> -----------------------------------------------------
>
> Key: TAP5-1407
> URL: https://issues.apache.org/jira/browse/TAP5-1407
> Project: Tapestry 5
> Issue Type: Improvement
> Components: tapestry-core
> Affects Versions: 5.2.4
> Reporter: Paul Stanton
> Fix For: 5.2.4
>
>
> Currently MultiZoneUpdate is a chain of MultiZoneUpdates, ie
> public class MultiZoneUpdate
> {
> ...
> public MultiZoneUpdate add(String zoneId, Object renderer)
> {
> return new MultiZoneUpdate(zoneId, renderer, this);
> }
> ...
> }
> usage:
> MultiZoneUpdate mzu = new MultiZoneUpdate("zone2", zone1); // ugly!
> mzu = mzu.add("zone2", zone2); // ugly!
> mzu = mzu.add("zone3", zone3); // ugly!
> ...
> return mzu;
> This becomes hard to use when event handlers call common methods which contribute zone updates.
> Also, it is possible to request multiple updates for the one zone which doesn't make much sense.
> In some cases it would be much easier if you could construct a MultiZoneUpdate object without actually contributing a zone update directive. ie:
> MultiZoneUpdate mzu = new MultiZoneUpdate();
> mzu.add("zone2", zone1);
> mzu.add("zone2", zone2);
> mzu.add("zone3", zone3);
> mzu.add("zone3", zone3); // knocks out prev zone3 update
> ...
> return mzu;
> I have created a utility class which helps me work around this issue (and issue #TAP5-1406), however note it relies on the dummy zone hack.:
> import java.util.HashMap;
> import java.util.Map.Entry;
> import org.apache.tapestry5.ComponentResources;
> import org.apache.tapestry5.MarkupWriter;
> import org.apache.tapestry5.ajax.MultiZoneUpdate;
> import org.apache.tapestry5.internal.services.PageRenderQueue;
> import org.apache.tapestry5.json.JSONObject;
> import org.apache.tapestry5.services.PartialMarkupRenderer;
> import org.apache.tapestry5.services.PartialMarkupRendererFilter;
> import org.apache.tapestry5.services.javascript.JavaScriptSupport;
> public class XHRResponseHelper
> {
> private HashMap<String, Object> zoneUpdates;
> private boolean scriptAdded;
> public XHRResponseHelper()
> {
> this.zoneUpdates = new HashMap<String, Object>();
> scriptAdded = false;
> }
> public void addScriptCall(final String script, PageRenderQueue pageRenderQueue, final JavaScriptSupport javascriptSupport)
> {
> scriptAdded = true;
> pageRenderQueue.addPartialMarkupRendererFilter(new PartialMarkupRendererFilter()
> {
> public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer)
> {
> javascriptSupport.addScript(script);
> renderer.renderMarkup(writer, reply);
> }
> });
> }
> public void addZoneUpdate(String zoneId, ComponentResources componentResources)
> {
> addZoneUpdate(zoneId, componentResources.getEmbeddedComponent(zoneId));
> }
> public void addZoneUpdate(String zoneId, Object renderer)
> {
> zoneUpdates.put(zoneId, renderer);
> }
> public MultiZoneUpdate buildMultiZoneUpdate(ComponentResources componentResources)
> {
> // work around issue - https://issues.apache.org/jira/browse/TAP5-1406
> if (zoneUpdates.isEmpty() && scriptAdded)
> addZoneUpdate("dummyZone", componentResources);
> MultiZoneUpdate mzu = null;
> for (Entry<String, Object> entry : zoneUpdates.entrySet())
> {
> if (mzu == null)
> mzu = new MultiZoneUpdate(entry.getKey(), entry.getValue());
> else
> mzu.add(entry.getKey(), entry.getValue());
> }
> return mzu; // null if zoneUpdates is empty
> }
> }
> usage:
> XHRResponseHelper response = new XHRResponseHelper();
> response.addZoneUpdate("myZone", componentResources);
> response.addZoneUpdate("myZone2", block);
> response.addScriptCall("alert('script');", pageRenderQueue, javascriptSupport);
> return response.buildMultiZoneUpdate(componentResources);
> hope that helps.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.