Hi Howard I submitted a patch for TAPS-1476 which is related to this issue.
https://issues.apache.org/jira/browse/TAP5-1476?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel regards Taha On Fri, Jul 8, 2011 at 6:32 AM, Howard M. Lewis Ship (JIRA) <[email protected] > wrote: > > [ > https://issues.apache.org/jira/browse/TAP5-1407?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel] > > Howard M. Lewis Ship reassigned TAP5-1407: > ------------------------------------------ > > Assignee: Howard M. Lewis Ship > > > 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 > > Assignee: Howard M. Lewis Ship > > > > 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 = 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. > For more information on JIRA, see: http://www.atlassian.com/software/jira > > > -- regards Tawus tawus.wordpress.com
