You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by ael <al...@dash.com.ph> on 2011/05/13 00:26:32 UTC

Auto Refresh Zone?

Is it possible to create a page with a zone but the content of the zone will
refresh automatically? I mean maybe every 10 seconds? Or should i create a
button then a javascript will click that button every 10 seconds?

What is the best options?


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Auto-Refresh-Zone-tp4391670p4391670.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Auto Refresh Zone?

Posted by Taha Tapestry <ta...@gmail.com>.
Use a periodical timer. There is an example in one of the mails in the mailing list

Regards
Taha

Sent from my iPhone

On May 13, 2011, at 3:56 AM, ael <al...@dash.com.ph> wrote:

> Is it possible to create a page with a zone but the content of the zone will
> refresh automatically? I mean maybe every 10 seconds? Or should i create a
> button then a javascript will click that button every 10 seconds?
> 
> What is the best options?
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Auto-Refresh-Zone-tp4391670p4391670.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

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


Re: Auto Refresh Zone?

Posted by ael <al...@dash.com.ph>.
Good Job Taha Thanks :)

Components

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dash.tapestryprogressupdate.components;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.AfterRender;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.internal.util.CaptureResultCallback;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;

/**
 *
 * @author alan
 */
@Import(library = "context:layout/js/progressbar.js")
public class ProgressBar {
    
   @Parameter(value = "1", defaultPrefix=BindingConstants.LITERAL)
   private int period;

   @Parameter(defaultPrefix = BindingConstants.LITERAL)
   private String clientFunc;

   @Inject
   private ComponentResources resources;

   @Environmental
   private JavaScriptSupport javaScriptSupport;

   @Inject
   private Request request;

   @AfterRender
   void afterRender(MarkupWriter writer){
      Link link = resources.createEventLink("timer");
      JSONObject spec = new JSONObject();
      spec.put("url", link.toAbsoluteURI());
      spec.put("period", period);
      spec.put("clientFunc", clientFunc);
      javaScriptSupport.addScript("new ProgressBar(%s);", spec);
   }

   Object onTimer(){
      JSONObject spec = new JSONObject();
      double value = 0.0;
      try {
         value = Double.parseDouble(request.getParameter("value"));
      }catch(NumberFormatException nfe){
         return spec;
      }

      CaptureResultCallback<Double> callback = new
      CaptureResultCallback<Double>();
      resources.triggerEvent("update", new Object[]{value}, callback);
      value = callback.getResult();
      System.out.println("Value = " + value);
      spec.put("value", value);
      return  spec;
   }

}


Javascript

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


ProgressBar = Class.create({
   initialize:function(spec){
      this.value = 0;
      this.url = spec.url;
      this.clientFunc = spec.clientFunc;
      this.executer = new PeriodicalExecuter(this.execute.bind(this),
spec.period);
   },

   execute:function(transport){
      new Ajax.Request(this.url + "?value=" + this.value, {
         method:"get",
         onSuccess:function(transport){
         this.onSuccess(transport);
         }.bind(this)
      }, this.period);
   },

   onSuccess:function(transport){
      var json = transport.responseText.evalJSON();
      if(typeof(json.value) == "undefined"){
      alert(transport.responseText + ": returned")
      this.stopExecuter();
      }
      this.value = json.value;
      if(this.clientFunc){
  var func = this.clientFunc +"(" + json.value+")";
  eval(func);
      }

      if(json.value >= 100){
     this.stopExecuter();
  }
   },

   stopExecuter:function(){
   this.executer.stop();
   }
});




Template

<p>  
    
        <t:progressbar t:id='progressBar' clientFunc='updateFunc'/>
        <div id='updateDiv'></div>
         
        
    </p>


Java Class


double onUpdateFromProgressBar(double percentage){
      return percentage + 10.0;
   } 




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Auto-Refresh-Zone-tp4391670p4392004.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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