<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7259901088221579649</id><updated>2011-07-08T14:45:02.451+02:00</updated><title type='text'>Tiny bits of code</title><subtitle type='html'>This blog is dedicated to the great Apache Tapestry web framework. I will use this blog to publish mixins and components that are:
&lt;ul&gt;
&lt;li&gt;Generally useful&lt;/li&gt;
&lt;li&gt;Good examples for learning Tapestry 5.&lt;/li&gt;
&lt;/ul&gt;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-1425132109773466165</id><published>2011-03-16T12:29:00.002+01:00</published><updated>2011-03-16T12:31:36.234+01:00</updated><title type='text'>ZoneUpdater - jQuery edition</title><content type='html'>I recently started using the excellent tapestry-jquery plugin that replaces prototype in T5. The internal implementation of zones in tapestry changes quite a bit in tapestry-jquery, so I had to change a couple of things in ZoneUpdater too. I find the updated code to be quite a bit better, here it is:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;var ZoneUpdater = function(spec) {&lt;br /&gt;&lt;br /&gt; var elementId = spec.elementId;&lt;br /&gt; var element = document.getElementById(elementId);&lt;br /&gt; var url = spec.url;&lt;br /&gt; var $zone = jQuery('#' + spec.zone);&lt;br /&gt;&lt;br /&gt; var updateZone = function() {&lt;br /&gt;  var updatedUrl = url;&lt;br /&gt;  var params = {};  &lt;br /&gt;  if (element.value) {&lt;br /&gt;   params.param = element.value;&lt;br /&gt;  }&lt;br /&gt;  $zone.tapestryZone('update', {&lt;br /&gt;   url : updatedUrl, &lt;br /&gt;   params : params&lt;br /&gt;  });&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; if (spec.event) {&lt;br /&gt;  var event = spec.event;&lt;br /&gt;  jQuery(element).bind(event, updateZone);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; return {&lt;br /&gt;  updateZone : updateZone&lt;br /&gt; };&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-1425132109773466165?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/1425132109773466165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2011/03/zoneupdater-jquery-edition.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/1425132109773466165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/1425132109773466165'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2011/03/zoneupdater-jquery-edition.html' title='ZoneUpdater - jQuery edition'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-940245753273674080</id><published>2010-05-21T10:31:00.006+02:00</published><updated>2010-06-02T09:42:35.013+02:00</updated><title type='text'>Mixin to allow any element to submit a form and trigger an event</title><content type='html'>I modified the builtin LinkSubmit component to be able to use the same thing on any element.&lt;br /&gt;&lt;br /&gt;I changed it to a mixin and did some other minor changes.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;@MixinAfter&lt;br /&gt;@IncludeJavaScriptLibrary("AnySubmit.js")&lt;br /&gt;public class AnySubmit {&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * The name of the event that will be triggered if this component is the cause of the form submission. The default&lt;br /&gt;   * is "selected".&lt;br /&gt;   */&lt;br /&gt;  @Parameter(allowNull = false, defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;  private String event = EventConstants.SELECTED;&lt;br /&gt;&lt;br /&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;  private String clientEvent = "change";&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * The value that will be made available to event handler method of this component when the form is&lt;br /&gt;   * submitted.&lt;br /&gt;   */&lt;br /&gt;  @Parameter&lt;br /&gt;  private Object context;&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * If true (the default), then any notification sent by the component will be deferred until the end of the form&lt;br /&gt;   * submission (this is usually desirable).&lt;br /&gt;   */&lt;br /&gt;  @Parameter&lt;br /&gt;  private boolean defer = true;&lt;br /&gt;&lt;br /&gt;  @InjectContainer&lt;br /&gt;  private ClientElement container;&lt;br /&gt;&lt;br /&gt;  @Inject&lt;br /&gt;  private ComponentResources resources;&lt;br /&gt;&lt;br /&gt;  @Inject&lt;br /&gt;  private RenderSupport renderSupport;&lt;br /&gt;&lt;br /&gt;  @Environmental&lt;br /&gt;  private FormSupport formSupport;&lt;br /&gt;&lt;br /&gt;  @Environmental&lt;br /&gt;  private Heartbeat heartbeat;&lt;br /&gt;&lt;br /&gt;  @Inject&lt;br /&gt;  private Request request;&lt;br /&gt;&lt;br /&gt;  @SuppressWarnings("serial")&lt;br /&gt;  private static class ProcessSubmission implements ComponentAction&lt;AnySubmit&gt; {&lt;br /&gt;&lt;br /&gt;    private final String clientId;&lt;br /&gt;&lt;br /&gt;    public ProcessSubmission(String clientId) {&lt;br /&gt;      this.clientId = clientId;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void execute(AnySubmit component) {&lt;br /&gt;      component.processSubmission(clientId);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  private void processSubmission(String clientId) {&lt;br /&gt;&lt;br /&gt;    String hiddenFieldName = clientId + ":hidden";&lt;br /&gt;&lt;br /&gt;    if (request.getParameter(hiddenFieldName) != null) {&lt;br /&gt;      final Object[] contextToPublish = getContext(request, clientId);&lt;br /&gt;      Runnable notification = new Runnable() {&lt;br /&gt;&lt;br /&gt;        public void run() {&lt;br /&gt;          resources.triggerEvent(event, contextToPublish, null);&lt;br /&gt;        }&lt;br /&gt;      };&lt;br /&gt;&lt;br /&gt;      if (defer)&lt;br /&gt;        formSupport.defer(notification);&lt;br /&gt;      else&lt;br /&gt;        heartbeat.defer(notification);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  private Object[] getContext(Request request, String clientId) {&lt;br /&gt;    String contextFieldName = clientId + ":context";&lt;br /&gt;    String context = request.getParameter(contextFieldName);&lt;br /&gt;    if (context != null) {&lt;br /&gt;      return new Object[] { context };&lt;br /&gt;    }&lt;br /&gt;    String value = request.getParameter(clientId);&lt;br /&gt;    if (value != null) {&lt;br /&gt;      return new Object[] { value };&lt;br /&gt;    }&lt;br /&gt;    return null;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  void beginRender() {&lt;br /&gt;    formSupport.store(this, new ProcessSubmission(container.getClientId()));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  void afterRender(MarkupWriter writer) {&lt;br /&gt;    renderSupport.addInit("anySubmit", formSupport.getClientId(), container.getClientId(), clientEvent);&lt;br /&gt;    if (context != null) {&lt;br /&gt;      writer.element("input", "type", "hidden", "value", context, "name", container.getClientId() + ":context");&lt;br /&gt;      writer.end();&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tapestry.AnySubmit = Class.create({&lt;br /&gt;&lt;br /&gt;    initialize: function(formId, clientId, event)&lt;br /&gt;    {&lt;br /&gt;        this.form = $(formId);&lt;br /&gt;        this.element = $(clientId);&lt;br /&gt;&lt;br /&gt;        this.element.observe(event, this.onEvent.bindAsEventListener(this));&lt;br /&gt;    },&lt;br /&gt;&lt;br /&gt;    createHidden : function()&lt;br /&gt;    {&lt;br /&gt;        var hidden = new Element("input", { "type":"hidden",&lt;br /&gt;            "name": this.element.id + ":hidden",&lt;br /&gt;            "value": this.element.id});&lt;br /&gt;&lt;br /&gt;        this.element.insert({after:hidden});&lt;br /&gt;    },&lt;br /&gt;&lt;br /&gt;    onEvent : function(event)&lt;br /&gt;    {&lt;br /&gt;        Event.stop(event);&lt;br /&gt;&lt;br /&gt;        var onsubmit = this.form.onsubmit;&lt;br /&gt;&lt;br /&gt;        if (onsubmit == undefined || onsubmit.call(window.document, event))&lt;br /&gt;        {&lt;br /&gt;            this.createHidden();&lt;br /&gt;            this.form.submit();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return false;&lt;br /&gt;    }&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;Tapestry.Initializer.anySubmit = function(formId, clientId, event)&lt;br /&gt;{&lt;br /&gt;    new Tapestry.AnySubmit(formId, clientId, event);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-940245753273674080?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/940245753273674080/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2010/05/mixin-to-allow-any-element-to-submit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/940245753273674080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/940245753273674080'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2010/05/mixin-to-allow-any-element-to-submit.html' title='Mixin to allow any element to submit a form and trigger an event'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-2344238827486213497</id><published>2010-03-15T09:24:00.006+01:00</published><updated>2010-03-15T09:28:10.099+01:00</updated><title type='text'>Check all mixin</title><content type='html'>This is a VERY simple mixin that turns a regular checkbox into a controller checkbox. It's a nice example of how easy it is to create these elegant little mixins and components in Tapestry 5!&lt;br /&gt;&lt;br /&gt;Example: &amp;lt;input type="checkkbox" t:type="any" t:mixins="checkall" t:controlledClass="element-selected"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;CheckAll.java&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/**&lt;br /&gt; * Mixin for checkboxes that should control the checked state of a group of other checkboxes. All the controlled checkboxes need to&lt;br /&gt; * have the CSS class specified in the &lt;code&gt;controlledClass&lt;/code&gt; parameter. &lt;br /&gt; * &lt;br /&gt; * @author Inge&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class CheckAll {&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * The controller checkbox that this mixin applies to.&lt;br /&gt;   */&lt;br /&gt;  @InjectContainer&lt;br /&gt;  private ClientElement container;&lt;br /&gt;&lt;br /&gt;  @Environmental&lt;br /&gt;  private RenderSupport renderSupport;&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * The CSS class that all controlled checkboxes must have to be controlled by the master checkbox.&lt;br /&gt;   */&lt;br /&gt;  @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;  private String controlledClass;&lt;br /&gt;&lt;br /&gt;  void afterRender() {&lt;br /&gt;    renderSupport.addScript("new CheckAll('%s', '%s')", container.getClientId(), controlledClass);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;CheckAll.js&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var CheckAll = Class.create( {&lt;br /&gt; initialize : function(controllerId, controlledClass) {&lt;br /&gt;  this.controller = $(controllerId);&lt;br /&gt;  this.controlledClass = controlledClass;&lt;br /&gt;  this.controller.observe('change', this.toggle.bindAsEventListener(this));&lt;br /&gt; },&lt;br /&gt; toggle: function() {&lt;br /&gt;  var checked = this.controller.checked;&lt;br /&gt;  var controlledCheckboxes = $$('input.' + this.controlledClass);&lt;br /&gt;  controlledCheckboxes.each(function(checkbox) {&lt;br /&gt;   checkbox.checked = checked;&lt;br /&gt;  });&lt;br /&gt; }&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-2344238827486213497?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/2344238827486213497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2010/03/check-all-mixin.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/2344238827486213497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/2344238827486213497'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2010/03/check-all-mixin.html' title='Check all mixin'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-6689364344953474476</id><published>2010-03-05T08:52:00.004+01:00</published><updated>2010-03-05T09:04:13.454+01:00</updated><title type='text'>New and better (?) ZoneUpdater</title><content type='html'>I recently sat down and did some evaluation of the &lt;a href="http://tinybits.blogspot.com/2009/05/update-zone-on-any-client-side-event.html"&gt;ZoneUpdater&lt;/a&gt; code. I found that it is a bit hard to configure and debug, so I decided to do a little refactoring to trade some flexibility for readability and usability. &lt;br /&gt;&lt;br /&gt;I also wanted to add a missing feature, the ability to update a zone simply by calling a javascript function. This is a nice way of "object orienting" different features/sections on a page, by giving different sections their own client API that they can communicate with.&lt;br /&gt;&lt;br /&gt;Most important changes:&lt;br /&gt;- Removed support for specifying another listening element than the container&lt;br /&gt;- Cleaner code&lt;br /&gt;- Request parameter instead of encoding parameter into link context.&lt;br /&gt;- Generates a javascript variable to easy zone update through javascript.&lt;br /&gt;&lt;br /&gt;I also wanted to add an internal listener that triggers the actual event with context, so the page/component listener doesn't have to inject the Request and do request.getParameter("param"). Didn't succeed so far.&lt;br /&gt;&lt;br /&gt;Anyway, here's the modified code. No code formatting this time, but it should be short enough to be readable. Enjoy :)&lt;br /&gt;&lt;br /&gt;ZoneUpdater.java&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;@IncludeJavaScriptLibrary( { "ZoneUpdater.js" })&lt;br /&gt;public class ZoneUpdater {&lt;br /&gt;&lt;br /&gt;  @Inject&lt;br /&gt;  private ComponentResources resources;&lt;br /&gt;&lt;br /&gt;  @Environmental&lt;br /&gt;  private RenderSupport renderSupport;&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * The event to listen for on the client. If not specified, zone update can only be triggered manually through calling updateZone on the JS object.&lt;br /&gt;   */&lt;br /&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;  private String clientEvent;&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * The event to listen for in your component class&lt;br /&gt;   */&lt;br /&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL, required = true)&lt;br /&gt;  private String event;&lt;br /&gt;&lt;br /&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL, value = "default")&lt;br /&gt;  private String prefix;&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * The element we attach ourselves to&lt;br /&gt;   */&lt;br /&gt;  @InjectContainer&lt;br /&gt;  private ClientElement element;&lt;br /&gt;&lt;br /&gt;  @Parameter&lt;br /&gt;  private Object[] context;&lt;br /&gt;&lt;br /&gt;  /**&lt;br /&gt;   * The zone to be updated by us.&lt;br /&gt;   */&lt;br /&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL, required = true)&lt;br /&gt;  private String zone;&lt;br /&gt;&lt;br /&gt;  void afterRender() {&lt;br /&gt;    String url = resources.createEventLink(event, context).toAbsoluteURI();&lt;br /&gt;    String elementId = element.getClientId();&lt;br /&gt;    JSONObject spec = new JSONObject();&lt;br /&gt;    spec.put("url", url);&lt;br /&gt;    spec.put("elementId", elementId);&lt;br /&gt;    spec.put("event", clientEvent);&lt;br /&gt;    spec.put("zone", zone);&lt;br /&gt;&lt;br /&gt;    renderSupport.addScript("%sZoneUpdater = new ZoneUpdater(%s)", prefix, spec.toString());&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ZoneUpdater.js&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var ZoneUpdater = Class.create({&lt;br /&gt; initialize: function(spec) {&lt;br /&gt;  this.element = $(spec.elementId);  &lt;br /&gt;  this.url = spec.url;&lt;br /&gt;  $T(this.element).zoneId = spec.zone;   &lt;br /&gt;  if (spec.event) {&lt;br /&gt;   this.event = spec.event;&lt;br /&gt;   this.element.observe(this.event, this.updateZone.bindAsEventListener(this));&lt;br /&gt;  }&lt;br /&gt; }, &lt;br /&gt; updateZone: function() {&lt;br /&gt;     var zoneManager = Tapestry.findZoneManager(this.element);&lt;br /&gt;     if ( !zoneManager ) return;&lt;br /&gt;     &lt;br /&gt;     var updatedUrl = this.url;&lt;br /&gt;     if (this.element.value) {&lt;br /&gt;      var param = this.element.value;&lt;br /&gt;      if (param) {&lt;br /&gt;       updatedUrl = addParameter('param', param, updatedUrl); // You need to provide your own function for this...&lt;br /&gt;      }&lt;br /&gt;     }          &lt;br /&gt;     zoneManager.updateFromURL(updatedUrl);  &lt;br /&gt; }&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-6689364344953474476?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/6689364344953474476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2010/03/new-and-better-zoneupdater.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/6689364344953474476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/6689364344953474476'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2010/03/new-and-better-zoneupdater.html' title='New and better (?) ZoneUpdater'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-7895639790415784573</id><published>2009-10-20T22:04:00.001+02:00</published><updated>2009-10-20T22:05:03.750+02:00</updated><title type='text'>Link with confirmation</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This is&amp;#160; a component that adds confirmation to a regular EventLink. It does this by using the TapestryExt.js library introduced in my previous post to trigger a link after intercepting and cancelling it first. It works both with and without zones.&lt;/p&gt;  &lt;p&gt;It is used excactly like an EventLink, with an additional “message” parameter, to display in confirmation box.&lt;/p&gt;  &lt;p&gt;For now, I only implemented a standard javascript confirm box. But it shouldn’t be too hard extending this with more fancy interaction with DHTML.&lt;/p&gt;  &lt;p&gt;I’m not completely comfortable with the techniques used here. Some of it looks a lot like a hack in my opinion, especially the part about intercepting/cancelling a zone listener and re-adding it afterwards using copy-paste from tapestry.js.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ConfirmLink.java:&lt;/strong&gt;&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 800px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;/**&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; * Displays a javascript confirmation box before actually triggering the link.&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; * &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; * @author Inge&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; *&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;@IncludeJavaScriptLibrary({&amp;quot;&lt;span style="color: #8b0000"&gt;TapestryExt.js, &lt;/span&gt;&amp;quot;ConfirmLink.js&amp;quot;&lt;span style="color: #8b0000"&gt;})&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;public &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ConfirmLink &lt;span style="color: #0000ff"&gt;implements&lt;/span&gt; ClientElement {    &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Environmental&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; RenderSupport renderSupport;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(&amp;quot;&lt;span style="color: #8b0000"&gt;literal:Do you really want to delete?&lt;/span&gt;&amp;quot;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String message;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Component(publishParameters=&amp;quot;&lt;span style="color: #8b0000"&gt;event,zone,context&lt;/span&gt;&amp;quot;, inheritInformalParameters=&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; EventLink confirmLink;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; afterRender() {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    String url = confirmLink.getLink().toRedirectURI();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    renderSupport.addScript(&amp;quot;&lt;span style="color: #8b0000"&gt;new ConfirmLink('%s', '%s', '%s')&lt;/span&gt;&amp;quot;, confirmLink.getClientId(), url, message);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; String getClientId() {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; confirmLink.getClientId();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;}&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;ConfirmLink.js&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 800px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; ConfirmLink = Class.create({&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  initialize: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(element, url, message) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element = $(element);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.url = url;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.message = message;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.initListeners = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.initListeners.bind(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.initListeners.defer();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #008000"&gt;// Makes it run after Tapestry:init to be able to delete&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #008000"&gt;// zone listener added by Tapestry and start listening for&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #008000"&gt;// our modded version instead.    &lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  },&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  onclick: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(event) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    Event.&lt;span style="color: #0000ff"&gt;stop&lt;/span&gt;(event);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;confirm&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.message)) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      TapestryExt.triggerLink(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.url);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  },&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  initListeners: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element.stopObserving('click'); &lt;span style="color: #008000"&gt;// Remove zone update, will be re-added later by TapestryExt.js.&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element.observe('click', &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.onclick.bindAsEventListener(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;));&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;});&lt;/pre&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-7895639790415784573?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/7895639790415784573/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2009/10/link-with-confirmation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/7895639790415784573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/7895639790415784573'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2009/10/link-with-confirmation.html' title='Link with confirmation'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-6985677833596251178</id><published>2009-10-16T08:24:00.007+02:00</published><updated>2009-10-20T21:56:11.913+02:00</updated><title type='text'>Missing javascript</title><content type='html'>&lt;p&gt;I think there are some important things missing from Tapestry.js to release the full potential of Tapetsry 5 and AJAX. I have started working on a javascript class, TapestryExt, that extends the functionality of Tapestry.js.    &lt;br /&gt;    &lt;br /&gt;My wish is to see all of this and more built in to tapestry.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 800px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #008000"&gt;/**&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; * Commonly needed functions that are absent in the default Tapestry js lib.&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; TapestryExt = {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #008000"&gt;/**&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   * If the specified form listens for the Tapestry.FORM_PROCESS_SUBMIT_EVENT event&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   * (all forms with a zone specified do), it will AJAX-submit and update its zone after.&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  submitZoneForm : &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(element) {    &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    element = $(element)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!element) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      Tapestry.error('Could not &lt;span style="color: #0000ff"&gt;find&lt;/span&gt; form to trigger AJAX submit on');&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    element.fire(Tapestry.FORM_PROCESS_SUBMIT_EVENT);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  },&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #008000"&gt;/**&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   * Trigger any link, zone or not. &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   * &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   * If no url is provided, the href attribute of element will be used.&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  triggerLink : &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(element, url) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    element = $(element);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!url) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      url = element.href;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }    &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!url) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      Tapestry.error('Unable to &lt;span style="color: #0000ff"&gt;find&lt;/span&gt; url to trigger on element ' + element.id);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; zoneObject = Tapestry.findZoneManager(element);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (zoneObject) {    &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      zoneObject.updateFromURL(url);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      &lt;span style="color: #008000"&gt;// Regular link&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      &lt;span style="color: #008000"&gt;// Note: this will skip all event observers on this link!&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      &lt;span style="color: #0000ff"&gt;window&lt;/span&gt;.&lt;span style="color: #0000ff"&gt;location&lt;/span&gt;.href = url;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  }  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-6985677833596251178?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/6985677833596251178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2009/10/missing-javascript.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/6985677833596251178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/6985677833596251178'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2009/10/missing-javascript.html' title='Missing javascript'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-109318868751023704</id><published>2009-05-21T01:13:00.001+02:00</published><updated>2009-05-21T01:13:50.156+02:00</updated><title type='text'>Simple OnEvent mixin</title><content type='html'>&lt;p&gt;This mixin is heavily based on Chenillekit OnEvent. I found that CK’s mixin had a different and too specific focus to fit my needs. I wanted to write an event mixin that does nothing but trigger an event. This is what I came up with, I believe the result is quite easy to understand, and should work as a nice foundation for other similar components and mixins.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;input type=”button” value=”Answer yes” t:type=”any” t:id=”yesButton” t:mixins=”onEvent” t:event=”click” callback=”updateStatus”/&amp;gt;&lt;/p&gt;  &lt;p&gt;Object onClickFromYesButton() {&lt;/p&gt;  &lt;p&gt;return “Positive”; // Arguments for javascript function “updateStatus”&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;OnEvent.java&lt;/strong&gt;&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;@IncludeJavaScriptLibrary(&amp;quot;&lt;span style="color: #8b0000"&gt;OnEvent.js&lt;/span&gt;&amp;quot;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; OnEvent {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(required = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String event;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Object[] context;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Environmental&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; RenderSupport renderSupport;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @InjectContainer&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ClientElement container;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String callback;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Inject&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ComponentResources componentResources;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; afterRender() {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    Link link = componentResources.createEventLink(event, context);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    String script = &amp;quot;&lt;span style="color: #8b0000"&gt;new OnEvent('%s', '%s', '%s', '%s')&lt;/span&gt;&amp;quot;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    renderSupport.addScript(script, container.getClientId(), event, link.toRedirectURI(), callback);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;OnEvent.js&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; OnEvent = Class.create({&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    initialize: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(elementId, event, url, callback)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!$(elementId))&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            &lt;span style="color: #0000ff"&gt;throw&lt;/span&gt;(elementId + &amp;quot;&lt;span style="color: #8b0000"&gt; doesn't exist!&lt;/span&gt;&amp;quot;);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element = $(elementId);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.callback = callback;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.url = url;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element.observe(event, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.eventHandler.bindAsEventListener(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;));&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    },&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    eventHandler: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(event)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Ajax.Request(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.url, {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            method: 'get',&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;			onFailure: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(t)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('Error communication &lt;span style="color: #0000ff"&gt;with&lt;/span&gt; the server: ' + t.responseText.stripTags());&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            },&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            onException: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(t, exception)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('Error communication &lt;span style="color: #0000ff"&gt;with&lt;/span&gt; the server: ' + exception.message);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            },&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            onSuccess: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(t)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;            {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.callback)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;				{&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;					&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; funcToEval = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.callback + &amp;quot;&lt;span style="color: #8b0000"&gt;(&lt;/span&gt;&amp;quot; + t.responseText + &amp;quot;&lt;span style="color: #8b0000"&gt;)&lt;/span&gt;&amp;quot;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;					&lt;span style="color: #0000ff"&gt;eval&lt;/span&gt;(funcToEval);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;				}&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;			}.bind(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;        });&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;});&lt;/pre&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-109318868751023704?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/109318868751023704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2009/05/simple-onevent-mixin.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/109318868751023704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/109318868751023704'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2009/05/simple-onevent-mixin.html' title='Simple OnEvent mixin'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-8891736136161994236</id><published>2009-05-15T11:08:00.001+02:00</published><updated>2009-05-19T10:19:15.846+02:00</updated><title type='text'>Update a zone on any client side event</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;input type=”text” t:type=”textField” value=”myValue” t:mixins=”zoneUpdater” zone=”searchResultZone” event=”performSearch” clientEvent=”onkeyup”/&amp;gt;&lt;/p&gt;  &lt;p&gt;Then all you have to do is providing a listener method for the performSearch-event in your component/page class.&lt;/p&gt;  &lt;p&gt;There is some room for improvement here in terms of more flexibility on event link context and other things. But it works.&lt;/p&gt;  &lt;p&gt;There might be improvements in the Tapestry js library to make it easier to obtain and trigger zones. This code was developed with T 5.0.18.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ZoneUpdater.java&lt;/strong&gt;&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;@IncludeJavaScriptLibrary(&amp;quot;&lt;span style="color: #8b0000"&gt;ZoneUpdater.js&lt;/span&gt;&amp;quot;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ZoneUpdater {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;final&lt;/span&gt; String PLACEHOLDER = &amp;quot;&lt;span style="color: #8b0000"&gt;XXX&lt;/span&gt;&amp;quot;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Inject&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ComponentResources resources;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Environmental&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; RenderSupport renderSupport;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String clientEvent;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL, required = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String event;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @InjectContainer&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ClientElement element;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Object[] context;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #008000"&gt;// To enable popups to fire events on this document, enter &amp;quot;document&amp;quot; here.&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String listeningElement;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL, required = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String zone;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; Link createLink(Object[] context) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (context == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      context = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Object[1];&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    context = ArrayUtils.add(context, PLACEHOLDER); &lt;span style="color: #008000"&gt;// To be replaced by javascript&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; resources.createEventLink(event, context);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; afterRender() {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    String link = createLink(context).toAbsoluteURI();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    String elementId = element.getClientId();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (clientEvent == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      clientEvent = event;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (listeningElement == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;      listeningElement = &amp;quot;&lt;span style="color: #8b0000"&gt;$('&lt;/span&gt;&amp;quot; + elementId + &amp;quot;'&lt;span style="color: #8b0000"&gt;)&lt;/span&gt;&amp;quot;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    renderSupport.addScript(&amp;quot;&lt;span style="color: #8b0000"&gt;new ZoneUpdater('%s', %s, '%s', '%s', '%s', '%s')&lt;/span&gt;&amp;quot;, elementId, listeningElement, clientEvent, link, zone, PLACEHOLDER);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;ZoneUpdater.js&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; ZoneUpdater = Class.create();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;ZoneUpdater.&lt;span style="color: #0000ff"&gt;prototype&lt;/span&gt; = {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	initialize: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(zoneElementId, listeningElement, event, link, zone, placeholder) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.zoneElement = $(zoneElementId);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.event = event;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.link = link;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.placeholder = placeholder;		&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		$T(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.zoneElement).zoneId = zone;			&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		listeningElement.observe(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.event, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.updateZone.bindAsEventListener(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;));&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	},	&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	updateZone: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(event) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; zoneObject = Tapestry.findZoneManager(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.zoneElement);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( !zoneObject ) &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; param;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.zoneElement.value) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    	param = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.zoneElement.value;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!param) param = ' ';&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    param = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.encodeForUrl(param);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; updatedLink = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.link.gsub(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.placeholder, param);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    zoneObject.updateFromURL(updatedLink);		&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	},&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	encodeForUrl: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(string) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #008000"&gt;/**&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		 * See equanda.js for updated version of this&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		 */&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		string = string.replace(/\r\n/g,&amp;quot;&lt;span style="color: #8b0000"&gt;\n&lt;/span&gt;&amp;quot;);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; res = &amp;quot;&lt;span style="color: #8b0000"&gt;&lt;/span&gt;&amp;quot;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; n = 0; n &amp;lt; string.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt;; n++)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; c = string.charCodeAt( n );&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( '$' == string.charAt( n ) )&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	            res += '$$';&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ( &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.inRange( c, &amp;quot;&lt;span style="color: #8b0000"&gt;AZ&lt;/span&gt;&amp;quot; ) || &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.inRange( c, &amp;quot;&lt;span style="color: #8b0000"&gt;az&lt;/span&gt;&amp;quot; ) || &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.inRange( c, &amp;quot;&lt;span style="color: #8b0000"&gt;09&lt;/span&gt;&amp;quot; ) || &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.inRange( c, &amp;quot;&lt;span style="color: #8b0000"&gt;..&lt;/span&gt;&amp;quot; ) )&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	            res += string.charAt( n )&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	            &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; tmp = c.&lt;span style="color: #0000ff"&gt;toString&lt;/span&gt;(16);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	            &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; ( tmp.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt; &amp;lt; 4 ) tmp = &amp;quot;&lt;span style="color: #8b0000"&gt;0&lt;/span&gt;&amp;quot; + tmp;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	            res += '$' + tmp;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	        }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; res;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	},&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	inRange: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(code, range) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; code &amp;gt;= range.charCodeAt( 0 ) &amp;amp;&amp;amp;  code &amp;lt;= range.charCodeAt( 1 );&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	}&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-8891736136161994236?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/8891736136161994236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2009/05/update-zone-on-any-client-side-event.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/8891736136161994236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/8891736136161994236'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2009/05/update-zone-on-any-client-side-event.html' title='Update a zone on any client side event'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-4101417063506364851</id><published>2009-04-15T14:34:00.001+02:00</published><updated>2009-05-21T01:20:12.739+02:00</updated><title type='text'>Open a page in a popup window</title><content type='html'>&lt;p&gt;This mixin can be applied to any element that has an onclick event. It opens the specified page in a new window. There is room for more parameters here for styling the window, and possibly for using other events than onclick as a trigger.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;input type=”button” value=”View shopping cart” t:mixins=”popupPageLink” page=”cart/view” context=”cartId”/&amp;gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Java:&lt;/strong&gt;&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.BindingConstants;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.ClientElement;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.ComponentResources;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.Link;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.RenderSupport;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.annotations.Environmental;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.annotations.InjectContainer;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.annotations.Parameter;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;import&lt;/span&gt; org.apache.tapestry5.ioc.annotations.Inject;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;@IncludeJavaScriptLibrary(&amp;quot;&lt;span style="color: #8b0000"&gt;PopupPageLink.js&lt;/span&gt;&amp;quot;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; PopupPageLink {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Inject&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ComponentResources resources;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Environmental&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; RenderSupport renderSupport;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @InjectContainer&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ClientElement container;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(required = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, defaultPrefix = BindingConstants.LITERAL)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String page;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL, value=&amp;quot;&lt;span style="color: #8b0000"&gt;800&lt;/span&gt;&amp;quot;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String width;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter(defaultPrefix = BindingConstants.LITERAL, value=&amp;quot;&lt;span style="color: #8b0000"&gt;600&lt;/span&gt;&amp;quot;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; String height;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  @Parameter&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Object[] context;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; afterRender() {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    Link link = resources.createPageLink(page, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;, context);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;    renderSupport.addScript(&amp;quot;&lt;span style="color: #8b0000"&gt;new PopupPageLink('%s', '%s', %s, %s);&lt;/span&gt;&amp;quot;, container.getClientId(), link, width, height);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Javascript:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; PopupPageLink = Class.create();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;PopupPageLink.&lt;span style="color: #0000ff"&gt;prototype&lt;/span&gt; = {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	initialize: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(id, link, width, height) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element = $(id);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.link = link;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.width = width;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.height = height;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		Event.observe(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element, 'click', &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.onclick.bindAsEventListener(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;));&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	},&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	onclick: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt;	&lt;span style="color: #0000ff"&gt;name&lt;/span&gt; = 'dialogWindow';&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; win = &lt;span style="color: #0000ff"&gt;window&lt;/span&gt;.&lt;span style="color: #0000ff"&gt;open&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.link,&lt;span style="color: #0000ff"&gt;name&lt;/span&gt;,'width=' + &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.width + ',height=' + &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.height + ',resizable=yes,&lt;span style="color: #0000ff"&gt;scrollbars&lt;/span&gt;=yes,&lt;span style="color: #0000ff"&gt;menubar&lt;/span&gt;=no,screenX=0,screenY=0,left=0,&lt;span style="color: #0000ff"&gt;top&lt;/span&gt;=0' );&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	    win.&lt;span style="color: #0000ff"&gt;focus&lt;/span&gt;();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;	}&lt;br /&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-4101417063506364851?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/4101417063506364851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2009/04/open-page-in-popup-window.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/4101417063506364851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/4101417063506364851'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2009/04/open-page-in-popup-window.html' title='Open a page in a popup window'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7259901088221579649.post-5200485286309523909</id><published>2009-04-15T14:15:00.001+02:00</published><updated>2009-04-15T14:25:43.771+02:00</updated><title type='text'>Enforce max length on textareas and textfields</title><content type='html'>&lt;p&gt;This is a mixin that can be used to enforce the maximum content length of any textarea or text input. It uses javascript to chop off any character that exceeds the given maxlength.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;textarea t:type=&amp;quot;textarea&amp;quot; t:mixins=&amp;quot;maxlength&amp;quot; max=&amp;quot;100&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;MaxLength.java&lt;/strong&gt;&lt;/p&gt;  &lt;pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 650px; padding-top: 5px; border-bottom: #cecece 1px solid; background-color: #fbfbfb"&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;&lt;span style="color: #008000"&gt;/**&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; * Enforces maxlength on a textfield or a textarea&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; * &lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; * @author Inge&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; *&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;@IncludeJavaScriptLibrary(&amp;quot;&lt;span style="color: #8b0000"&gt;MaxLength.js&lt;/span&gt;&amp;quot;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MaxLength {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  @InjectContainer&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ClientElement container;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  @Parameter(required=&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; max;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  @Parameter(&amp;quot;&lt;span style="color: #8b0000"&gt;true&lt;/span&gt;&amp;quot;)&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;boolean&lt;/span&gt; displayCounter;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  @Environmental&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; RenderSupport renderSupport;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; afterRender(MarkupWriter writer) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    String id = container.getClientId();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    String counterId = id + &amp;quot;&lt;span style="color: #8b0000"&gt;-counter&lt;/span&gt;&amp;quot;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    writer.element(&amp;quot;&lt;span style="color: #8b0000"&gt;div&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;id&lt;/span&gt;&amp;quot;, counterId + &amp;quot;&lt;span style="color: #8b0000"&gt;-container&lt;/span&gt;&amp;quot;);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!displayCounter) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;      writer.attributes(&amp;quot;&lt;span style="color: #8b0000"&gt;style&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;display: none&lt;/span&gt;&amp;quot;);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    writer.element(&amp;quot;&lt;span style="color: #8b0000"&gt;input&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;type&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;text&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;id&lt;/span&gt;&amp;quot;, counterId, &amp;quot;&lt;span style="color: #8b0000"&gt;disabled&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;disabled&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;size&lt;/span&gt;&amp;quot;, &amp;quot;&lt;span style="color: #8b0000"&gt;3&lt;/span&gt;&amp;quot;);    &lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    writer.end();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    writer.end();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;    renderSupport.addScript(&amp;quot;&lt;span style="color: #8b0000"&gt;new MaxLength('%s', '%s', %s)&lt;/span&gt;&amp;quot;, id, counterId, max);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;}&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&amp;#160;&lt;strong&gt;MaxLenght.js&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 650px; padding-top: 5px; border-bottom: #cecece 1px solid; background-color: #fbfbfb"&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; MaxLength = Class.create();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;MaxLength.&lt;span style="color: #0000ff"&gt;prototype&lt;/span&gt; = {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;	initialize: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(id, counterId, max) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.max = max;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element = $(id);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element.observe('keyup', &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.keyup.bindAsEventListener(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;));&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.counterElement = $(counterId);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.updateCounter();		&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;	},&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;	keyup: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(event) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element.value.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt; &amp;gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.max) {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;			&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element.value = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element.value.substring(0, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.max);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		}&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.updateCounter();&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;	},&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;	updateCounter: &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() {&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; currentLength = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.element.value.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.counterElement.value = (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.max - currentLength);&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;	}&lt;br /&gt;&lt;/pre&gt;&lt;pre style="font-size: 12px; margin: 0em; width: 100%; font-family: consolas,&amp;#39;Courier New&amp;#39;,courier,monospace; background-color: #fbfbfb"&gt;}&lt;/pre&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7259901088221579649-5200485286309523909?l=tinybits.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tinybits.blogspot.com/feeds/5200485286309523909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://tinybits.blogspot.com/2009/04/enforce-max-length-on-textareas-and_15.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/5200485286309523909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7259901088221579649/posts/default/5200485286309523909'/><link rel='alternate' type='text/html' href='http://tinybits.blogspot.com/2009/04/enforce-max-length-on-textareas-and_15.html' title='Enforce max length on textareas and textfields'/><author><name>ingesol</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
