Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-1405

XHR requests should be easily callable from javascript and not rely on a zone

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2
    • Fix Version/s: 5.4
    • Component/s: tapestry-core
    • Labels:
      None

      Description

      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

      EG

      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);
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                hlship Howard M. Lewis Ship
                Reporter:
                paul.stanton Paul Stanton
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: