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-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org