tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Stanton (JIRA)" <j...@apache.org>
Subject [jira] Created: (TAP5-1405) XHR requests should be easily callable from javascript and not rely on a zone
Date Fri, 07 Jan 2011 07:09:48 GMT
XHR requests should be easily callable from javascript and not rely on a zone

                 Key: TAP5-1405
                 URL: https://issues.apache.org/jira/browse/TAP5-1405
             Project: Tapestry 5
          Issue Type: Improvement
          Components: tapestry-core
    Affects Versions: 5.2.4
            Reporter: Paul Stanton

I quite often needed to initialise an XHR request-response from javascript. I think it would
be a very useful feature for tapestry to expose to it's users.

The ideal solution would
1. not require a zone for wiring (see #TAP5-1404)
2. encode context parameters as per server side


I ended up writing a function to facilitate this. It handles:

  1. the zone wiring
  2. context parameters (unfortunately does not properly conform to encoding rules as per
server side generated params)
  3. query strings (sometimes useful)
  4. url based session ids (for when cookies are disabled)

note that the url is usually generated at the server side via ComponentResources.createEventLink.

function multiZoneUpdate(url, params, zoneId)
// wire up zone, use dummy if none supplied
    if (typeof(zoneId) == "undefined")
        zoneId = "dummyZone";
    var zoneObject = Tapestry.findZoneManagerForZone(zoneId);
    if (!zoneObject)
        throw "unknown zone: " + zoneId;

// context params must be an array
    if (!(params instanceof Array))
        params = [params];

// include query string if supplied
    var qs = "";
    var qsInd = url.indexOf("?");
    if (qsInd != -1)
        qs = url.substring(qsInd);
        url = url.substring(0, qsInd);

// include jsessionid if exists
    var jsId = "";
    var jsInd = url.indexOf(";");
    if (jsInd != -1)
        jsId = url.substring(jsInd);
        url = url.substring(0, jsInd);

// build url
    if (params != null)
        for (var p = 0; p < params.length; p++)
            url += "/" + params[p];

// request
    zoneObject.updateFromURL(url + jsId + qs);

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message