I use my own implementation for Periodic display which displays a block till 
you return null from the event handler . It is for tapestry-jquery, so you will 
have to change the js from jquery to prototype. 

(I am not sure it will help because of the size of the code :). May be I will 
write a post about it tomorrow )

@Import(library = "ProgressiveDisplay2.js")
public class ProgressiveDisplay2 implements ClientElement {

  private static final String PROGRESSIVE_DISPLAY_INTERNAL =
          EventConstants.PROGRESSIVE_DISPLAY + "2";

  @Parameter(value = "5", defaultPrefix = BindingConstants.LITERAL)
  private int period;

  @Parameter
  private Object[] context;

  @Parameter(value = "prop:componentResources.id", defaultPrefix = 
BindingConstants.LITERAL,
          allowNull = false)
  private String clientId;

  private String assignedClientId;

  @SuppressWarnings("UnusedDeclaration")
  Object[] defaultContext() {
      return new Object[]{};
  }

  @Parameter(defaultPrefix = BindingConstants.BLOCK)
  @Property
  private Block initial;

  @SuppressWarnings("UnusedDeclaration")
  Block defaultInitial() {
      return initialDefault;
  }

  @Inject
  private JavaScriptSupport javaScriptSupport;

  @Inject
  private ComponentResources resources;

  @Inject
  private AjaxResponseRenderer ajaxResponseRenderer;

  @InjectComponent
  private Zone zone;

  @Inject
  private Block initialDefault;

  @SetupRender
  void assignClientId(){
      assignedClientId = javaScriptSupport.allocateClientId(clientId);
  }

  @AfterRender
  void addJavaScript() {
      JSONObject specs = getArguments(getClientId(), context);

      javaScriptSupport.addInitializerCall("ProgressiveDisplay2", specs);
  }

  private JSONObject getArguments(String zoneId, Object[] context) {
      JSONObject specs = new JSONObject();

      specs.put("url", createUpdateURI(context));
      specs.put("period", period);
      specs.put("zoneId", zoneId);

      return specs;
  }

  private String createUpdateURI(Object [] context) {
      return resources.createEventLink(PROGRESSIVE_DISPLAY_INTERNAL, context)
              .toAbsoluteURI();
  }

  @OnEvent(PROGRESSIVE_DISPLAY_INTERNAL)
  private Object update(final EventContext context, @RequestParameter("zoneId") 
final String zoneId) {
      CaptureResultCallback<Object> callback = new 
CaptureResultCallback<Object>();

      boolean handled = resources.triggerContextEvent(
              EventConstants.PROGRESSIVE_DISPLAY,
              context, callback);

      if (handled && callback.getResult() == null) {
          ajaxResponseRenderer.addCallback(new JavaScriptCallback() {

              @Override
              public void run(JavaScriptSupport javaScriptSupport) {
                  javaScriptSupport.addInitializerCall("ProgressiveDisplay2", 
                          getArguments(zoneId, context.toStrings()));
              }

          });

          return zone.getBody();
      }

      return callback.getResult();
  }

  @Override
  public String getClientId() {
      return assignedClientId;
  }

}

(function ($) {

  $.extend(Tapestry.Initializer, {
      ProgressiveDisplay2:function (specs) {

          window.setTimeout(function () {

              console.log("window.timeout : " + specs.zoneId);
              var zone = $("#" + specs.zoneId);
              var params = {zoneId : specs.zoneId};
              zone.tapestryZone('update', { url:specs.url, params:params });

          }, specs.period * 1000);

      }
  });

})(jQuery);

<t:container xmlns:t='http://tapestry.apache.org/schema/tapestry_5_3.xsd'>

  <div t:type='Zone' t:id='zone' id='${clientId}'>
      <div t:type='Delegate' t:to='initial'/>
  </div>

  <t:block t:id='initialDefault'>
      Loading...
  </t:block>

</t:container>

Usage :-

<div t:type='ProgressiveDisplay2' t:context='...'>
              <p:initial>
                  <img src='' class='loading_thumbnail' alt=''/>
              </p:initial>
          </div>


@OnEvent(EventConstants.PROGRESSIVE_DISPLAY)
  public Object onUpload(Media media) {
      this.media = media;
      return media.isUploaded() ? thumbnailBlock : null;
  }

regards
Taha




On Jun 8, 2012, at 7:50 PM, tomandjerry wrote:

> I would like to keep the lastUpdated time in the browser so that new events
> can be propagated to the browser. For this I am using a Zone with
> zonerefresh mixin where I am trying to dynamically change the context passed
> to the ZoneRefresh mixin.
> 
> The below approach does not work. I appreciate if anyone has any other
> better way of solving this problem.
> 
> <t:zone t:id="poller" elementName="span" period="5" t:mixins="zoneRefresh"
> t:context="${time}">
>               
> </t:zone>
> 
> within the onRefresh event handler, I would like to change the 'time'  
> 
> Object onZoneRefresh(Object[] context) {
> ajaxRenderer.addCallback(new JavaScriptCallback() {
>                                               @Override
>                                               public void 
> run(JavaScriptSupport jsSupport) {
>                                                       JSONObject json = new 
> JSONObject();
>                                                       json.put("period", 5);
>                                                      json.put("URL",
> createEventLink(newTime));
>                                                       
> jsSupport.addInitializerCall(InitializationPriority.LATE,
> "zoneRefresh", json)
>                                               }
>                                       });
> }
> 
> private Object createEventLink(Long newTime){
>    Link link = resources.createEventLink("zoneRefresh", newTime);
>    return link.toAbsoluteURI();
>        }
> 
> --
> View this message in context: 
> http://tapestry.1045711.n5.nabble.com/Zone-Refresh-with-dynamic-context-tp5713719.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to