Re: multizone js xhr response

2010-05-24 Thread Josh Canfield
Ah, you're right. You can't add script during the action phase, you
need to add the script when the zones are rendering.

Try this:

@Inject
private RenderSupport _support;

@Inject
private PageRenderQueue _queue;

MultiZoneUpdate onHello() {
_queue.addPartialMarkupRendererFilter(new
PartialMarkupRendererFilter() {
public void renderMarkup(MarkupWriter writer, JSONObject
reply, PartialMarkupRenderer renderer) {
_support.addScript(alert('I am script'););
renderer.renderMarkup(writer, reply);
}
});
return new MultiZoneUpdate(test, _timeBlock);
}


Josh

On Sun, May 23, 2010 at 10:45 PM, Paul Stanton p...@mapshed.com.au wrote:
 Thanks for the ideas Josh, Hopefully I can get some use out of them...

 I am creating the Ajax.Request myself as this is essentially what the
 Autocompleter does which is the best example I can find. I am infact
 extending the Autocompleter so that I can trigger an Ajax communication when
 an item is selected from the autocomplete suggestions. Essentially this is
 the same as having an actionlink, in that I am using
 ComponentResources.createEventLink().toAbsoluteURI() to determine the URL to
 call via Ajax.Request. The listener on the other end returns the
 MultiZoneUpdate.

 I've tried injecting RenderSupport:
 @Inject private RenderSupport renderSupport;

 But the following exception is thrown:

 Caused by: java.lang.RuntimeException: No object of type
 org.apache.tapestry5.RenderSupport is available from the Environment.
  Available types are
 org.apache.tapestry5.services.ComponentEventResultProcessor.
   at
 org.apache.tapestry5.internal.services.EnvironmentImpl.peekRequired(EnvironmentImpl.java:79)
   at $Environment_128c8ccda65.peekRequired($Environment_128c8ccda65.java)
   at $Environment_128c8ccd9c6.peekRequired($Environment_128c8ccd9c6.java)
   at $RenderSupport_128c8ccda6d._delegate($RenderSupport_128c8ccda6d.java)
   at $RenderSupport_128c8ccda6d.addScript($RenderSupport_128c8ccda6d.java)
   at $RenderSupport_128c8ccda25.addScript($RenderSupport_128c8ccda25.java)

 I believe this is because it's invalid in the context of a partial render
 (ajax server side event listener). Have you tried injecting RenderSupport
 and using it in your example 'Object onActionFromUpdate()' ? I don't think
 it would work, because it is essentially the same architecture as what I
 have, minus the actionlink component.

 p.

 Josh Canfield wrote:

 I've recently come up with a solution for handling MultiZoneUpdate as the
 response from an Ajax.Request.


 I'm not sure I follow why you need to create your own Ajax.Request
 instead of using one of the built-in action/event link components. You
 can give it the name of one zone but return a MultiZoneUpdate
 response.

 (from tapestry core  MultiZoneUpdateDemo.tml )
    t:actionlink t:id=update zone=fredupdate/t:actionlink

 (from tapestry-core MultiZoneUpdateDemo.java)
  Object onActionFromUpdate()
    {
        return new MultiZoneUpdate(fred, fredBlock).add(barney,
 barneyBlock).add(dino, His dog, Dino.);
    }



 Now I need to add the ability to execute a script, generated (or values
 populated) by the server.



 @Inject RenderSupport and call the addScript methods. If you're using
 the built-in components then they get handled by default. The code
 that does that is in ZoneManager.processReply.

 Is this what you are trying to do?

 Josh

 On Sun, May 23, 2010 at 5:13 PM, Paul Stanton p...@mapshed.com.au wrote:


 Hi all,

 I've recently come up with a solution for handling MultiZoneUpdate as the
 response from an Ajax.Request.

 I did this by creating the following javascript function and calling it
 in
 Ajax.Request.onSuccess:

 Tapestry.handleMultizoneUpdate = function (transport)
 {
  var reply = transport.responseJSON;
  // copied from tapestry.js - ZoneManager.processReply
  // apparently exposed in t5.2
  Object.keys(reply.zones).each(function (zoneId) {
          var manager = Tapestry.findZoneManagerForZone(zoneId);
          if (manager) {
              var zoneContent = reply.zones[zoneId];
              manager.show(zoneContent);
          }
      });
 };

 Now I need to add the ability to execute a script, generated (or values
 populated) by the server.

 1. Where is the code that turns MultiZoneUpdate into JSON?
 2. What is the best way to return a javascript snippet from a tapestry
 event
 listener to the client and have it executed in an Ajax/XHR environment?

 Thanks, p.

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











-- 
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new 

Re: multizone js xhr response

2010-05-23 Thread Paul Stanton
I've found where the JSON is built, and can't see a way to include a 
script call anywhere in there.


So my first hacky inclination is to create a hidden zone who's innerHTML 
will contain the javascript (which has been updated in the server side 
event listener, and call it via something like 
'eval(zone.element.innerHTML);'.


In order to get this to work, I need to understand tapestry.js  
ZoneManager.show:


   show: function(content)
   {
   this.updateElement.update(content);

   var func = this.element.visible() ? this.updateFunc : this.showFunc;

   func.call(this, this.element, this.endcolor);

   this.element.fire(Tapestry.ZONE_UPDATED_EVENT);
   },

1. updates the innerHTML
2. then runs the show or update effect
3. fires Tapestry.ZONE_UPDATED_EVENT.

Therefore the most sensible place for me to place my handling code is in 
an event listener for Tapestry.ZONE_UPDATED_EVENT. Does anyone know 
how to attach a listener for this event?


p.

Paul Stanton wrote:

Hi all,

I've recently come up with a solution for handling MultiZoneUpdate as 
the response from an Ajax.Request.


I did this by creating the following javascript function and calling 
it in Ajax.Request.onSuccess:


Tapestry.handleMultizoneUpdate = function (transport)
{
   var reply = transport.responseJSON;
   // copied from tapestry.js - ZoneManager.processReply
   // apparently exposed in t5.2
   Object.keys(reply.zones).each(function (zoneId) {
   var manager = Tapestry.findZoneManagerForZone(zoneId);
   if (manager) {
   var zoneContent = reply.zones[zoneId];
   manager.show(zoneContent);
   }
   });
};

Now I need to add the ability to execute a script, generated (or 
values populated) by the server.


1. Where is the code that turns MultiZoneUpdate into JSON?
2. What is the best way to return a javascript snippet from a tapestry 
event listener to the client and have it executed in an Ajax/XHR 
environment?


Thanks, p.

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




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



Re: multizone js xhr response

2010-05-23 Thread Paul Stanton

I've answered my own question:

Tapestry.onDOMLoaded(function(){
   $(jsZone).observe(Tapestry.ZONE_UPDATED_EVENT, function(event){
  / find inner html and eval
   });
});

this does work ok, however I'm suspicious that there's an easier/tidier 
way to achieve the same already built in to tapestry...


???

Paul Stanton wrote:
I've found where the JSON is built, and can't see a way to include a 
script call anywhere in there.


So my first hacky inclination is to create a hidden zone who's 
innerHTML will contain the javascript (which has been updated in the 
server side event listener, and call it via something like 
'eval(zone.element.innerHTML);'.


In order to get this to work, I need to understand tapestry.js  
ZoneManager.show:


   show: function(content)
   {
   this.updateElement.update(content);

   var func = this.element.visible() ? this.updateFunc : 
this.showFunc;


   func.call(this, this.element, this.endcolor);

   this.element.fire(Tapestry.ZONE_UPDATED_EVENT);
   },

1. updates the innerHTML
2. then runs the show or update effect
3. fires Tapestry.ZONE_UPDATED_EVENT.

Therefore the most sensible place for me to place my handling code is 
in an event listener for Tapestry.ZONE_UPDATED_EVENT. Does anyone 
know how to attach a listener for this event?


p.

Paul Stanton wrote:

Hi all,

I've recently come up with a solution for handling MultiZoneUpdate as 
the response from an Ajax.Request.


I did this by creating the following javascript function and calling 
it in Ajax.Request.onSuccess:


Tapestry.handleMultizoneUpdate = function (transport)
{
   var reply = transport.responseJSON;
   // copied from tapestry.js - ZoneManager.processReply
   // apparently exposed in t5.2
   Object.keys(reply.zones).each(function (zoneId) {
   var manager = Tapestry.findZoneManagerForZone(zoneId);
   if (manager) {
   var zoneContent = reply.zones[zoneId];
   manager.show(zoneContent);
   }
   });
};

Now I need to add the ability to execute a script, generated (or 
values populated) by the server.


1. Where is the code that turns MultiZoneUpdate into JSON?
2. What is the best way to return a javascript snippet from a 
tapestry event listener to the client and have it executed in an 
Ajax/XHR environment?


Thanks, p.

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




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




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



Re: multizone js xhr response

2010-05-23 Thread Josh Canfield
 I've recently come up with a solution for handling MultiZoneUpdate as the
 response from an Ajax.Request.

I'm not sure I follow why you need to create your own Ajax.Request
instead of using one of the built-in action/event link components. You
can give it the name of one zone but return a MultiZoneUpdate
response.

(from tapestry core  MultiZoneUpdateDemo.tml )
t:actionlink t:id=update zone=fredupdate/t:actionlink

(from tapestry-core MultiZoneUpdateDemo.java)
 Object onActionFromUpdate()
{
return new MultiZoneUpdate(fred, fredBlock).add(barney,
barneyBlock).add(dino, His dog, Dino.);
}

 Now I need to add the ability to execute a script, generated (or values
 populated) by the server.


@Inject RenderSupport and call the addScript methods. If you're using
the built-in components then they get handled by default. The code
that does that is in ZoneManager.processReply.

Is this what you are trying to do?

Josh

On Sun, May 23, 2010 at 5:13 PM, Paul Stanton p...@mapshed.com.au wrote:
 Hi all,

 I've recently come up with a solution for handling MultiZoneUpdate as the
 response from an Ajax.Request.

 I did this by creating the following javascript function and calling it in
 Ajax.Request.onSuccess:

 Tapestry.handleMultizoneUpdate = function (transport)
 {
   var reply = transport.responseJSON;
   // copied from tapestry.js - ZoneManager.processReply
   // apparently exposed in t5.2
   Object.keys(reply.zones).each(function (zoneId) {
           var manager = Tapestry.findZoneManagerForZone(zoneId);
           if (manager) {
               var zoneContent = reply.zones[zoneId];
               manager.show(zoneContent);
           }
       });
 };

 Now I need to add the ability to execute a script, generated (or values
 populated) by the server.

 1. Where is the code that turns MultiZoneUpdate into JSON?
 2. What is the best way to return a javascript snippet from a tapestry event
 listener to the client and have it executed in an Ajax/XHR environment?

 Thanks, p.

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





-- 
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

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



Re: multizone js xhr response

2010-05-23 Thread Paul Stanton

Thanks for the ideas Josh, Hopefully I can get some use out of them...

I am creating the Ajax.Request myself as this is essentially what the 
Autocompleter does which is the best example I can find. I am infact 
extending the Autocompleter so that I can trigger an Ajax communication 
when an item is selected from the autocomplete suggestions. Essentially 
this is the same as having an actionlink, in that I am using 
ComponentResources.createEventLink().toAbsoluteURI() to determine the 
URL to call via Ajax.Request. The listener on the other end returns the 
MultiZoneUpdate.


I've tried injecting RenderSupport:
@Inject private RenderSupport renderSupport;

But the following exception is thrown:

Caused by: java.lang.RuntimeException: No object of type 
org.apache.tapestry5.RenderSupport is available from the Environment.  
Available types are 
org.apache.tapestry5.services.ComponentEventResultProcessor.
   at 
org.apache.tapestry5.internal.services.EnvironmentImpl.peekRequired(EnvironmentImpl.java:79)

   at $Environment_128c8ccda65.peekRequired($Environment_128c8ccda65.java)
   at $Environment_128c8ccd9c6.peekRequired($Environment_128c8ccd9c6.java)
   at $RenderSupport_128c8ccda6d._delegate($RenderSupport_128c8ccda6d.java)
   at $RenderSupport_128c8ccda6d.addScript($RenderSupport_128c8ccda6d.java)
   at $RenderSupport_128c8ccda25.addScript($RenderSupport_128c8ccda25.java)

I believe this is because it's invalid in the context of a partial 
render (ajax server side event listener). Have you tried injecting 
RenderSupport and using it in your example 'Object onActionFromUpdate()' 
? I don't think it would work, because it is essentially the same 
architecture as what I have, minus the actionlink component.


p.

Josh Canfield wrote:

I've recently come up with a solution for handling MultiZoneUpdate as the
response from an Ajax.Request.



I'm not sure I follow why you need to create your own Ajax.Request
instead of using one of the built-in action/event link components. You
can give it the name of one zone but return a MultiZoneUpdate
response.

(from tapestry core  MultiZoneUpdateDemo.tml )
t:actionlink t:id=update zone=fredupdate/t:actionlink

(from tapestry-core MultiZoneUpdateDemo.java)
 Object onActionFromUpdate()
{
return new MultiZoneUpdate(fred, fredBlock).add(barney,
barneyBlock).add(dino, His dog, Dino.);
}

  

Now I need to add the ability to execute a script, generated (or values
populated) by the server.




@Inject RenderSupport and call the addScript methods. If you're using
the built-in components then they get handled by default. The code
that does that is in ZoneManager.processReply.

Is this what you are trying to do?

Josh

On Sun, May 23, 2010 at 5:13 PM, Paul Stanton p...@mapshed.com.au wrote:
  

Hi all,

I've recently come up with a solution for handling MultiZoneUpdate as the
response from an Ajax.Request.

I did this by creating the following javascript function and calling it in
Ajax.Request.onSuccess:

Tapestry.handleMultizoneUpdate = function (transport)
{
  var reply = transport.responseJSON;
  // copied from tapestry.js - ZoneManager.processReply
  // apparently exposed in t5.2
  Object.keys(reply.zones).each(function (zoneId) {
  var manager = Tapestry.findZoneManagerForZone(zoneId);
  if (manager) {
  var zoneContent = reply.zones[zoneId];
  manager.show(zoneContent);
  }
  });
};

Now I need to add the ability to execute a script, generated (or values
populated) by the server.

1. Where is the code that turns MultiZoneUpdate into JSON?
2. What is the best way to return a javascript snippet from a tapestry event
listener to the client and have it executed in an Ajax/XHR environment?

Thanks, p.

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