You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lance Java <la...@googlemail.com> on 2012/07/10 22:18:27 UTC

Async process ComponentRequestHandler and JavaScriptSupport

I'm doing some very non standard stuff in tapestry-cometd where I need to
invoke tapestry's templating in an async thread. I do this by creating a
spoof request and response and setting RequestGlobals before invoking
ComponentRequestHandler.handleComponentEvent(ComponentEventRequestParameters).
This works well and I'm able to get a JSONObject with a "content" which
contains the html.

I'm now trying to support executing scripts added via JavaScriptSupport and
I'm running into troubles where a JavaScriptSupport instance is not
available in the Environment.

I was hoping that everything would just work but apparently I need to setup
the environment. Can any tapestry experts out there give me some advice on
what I'm missing and where I should copy / paste from? I'm hoping to get a
JSONObject with a "scripts" property that contains the scripts added via
JavaScriptSupport.

The service which does the magic is here
https://github.com/uklance/tapestry-cometd/blob/master/src/main/java/org/lazan/t5/cometd/services/internal/ComponentJsonRendererImpl.java

Cheers,
Lance.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Async-process-ComponentRequestHandler-and-JavaScriptSupport-tp5714401.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Async process ComponentRequestHandler and JavaScriptSupport

Posted by Lance Java <la...@googlemail.com>.
To answer my own question I needed to use AjaxResponseRenderer instead of
JavaScriptSupport and it all just works.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Async-process-ComponentRequestHandler-and-JavaScriptSupport-tp5714401p5714441.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Async process ComponentRequestHandler and JavaScriptSupport

Posted by Lance Java <la...@googlemail.com>.
Thanks for that Steve but it didn't work... it seems that a JavaScriptSupport
object has never been pushed onto the environment.

I get the following exception:
Caused by: java.lang.IllegalStateException: Stack is empty.
	at org.apache.tapestry5.ioc.util.Stack.checkIfEmpty(Stack.java:119)
	at org.apache.tapestry5.ioc.util.Stack.pop(Stack.java:106)
	at
org.apache.tapestry5.internal.services.EnvironmentImpl.decloak(EnvironmentImpl.java:139)
	at $Environment_511c6d86e27d.decloak(Unknown Source)
	at $Environment_511c6d86e1b5.decloak(Unknown Source)
	at
org.lazan.t5.cometd.services.internal.ComponentJsonRendererImpl$1.invoke(ComponentJsonRender

When I try the following:
JavaScriptSupport jss = null;
while (jss == null) {
	jss = environment.peek(JavaScriptSupport.class);
	if (jss == null) {
		environment.decloak();
		++ decloaks;
	}
}

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Async-process-ComponentRequestHandler-and-JavaScriptSupport-tp5714401p5714405.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Async process ComponentRequestHandler and JavaScriptSupport

Posted by Steve Eynon <st...@alienfactory.co.uk>.
Check that your Environment hasn't been cloaked().

During an Ajax call, when the phase switches from the action phase to
a render phase, the Env is `cloaked` effectively hiding all the stuff
previously put into the Env. This is new in 5.3 - quite annoying
really!

I added some hacky code to one project which, if pop() or peek()
returned null, I'd recursively decloak the Env until I found it. Then
re-cloak!

This may or may not be what you're running into.

Steve.

On 11 July 2012 04:18, Lance Java <la...@googlemail.com> wrote:
> I'm doing some very non standard stuff in tapestry-cometd where I need to
> invoke tapestry's templating in an async thread. I do this by creating a
> spoof request and response and setting RequestGlobals before invoking
> ComponentRequestHandler.handleComponentEvent(ComponentEventRequestParameters).
> This works well and I'm able to get a JSONObject with a "content" which
> contains the html.
>
> I'm now trying to support executing scripts added via JavaScriptSupport and
> I'm running into troubles where a JavaScriptSupport instance is not
> available in the Environment.
>
> I was hoping that everything would just work but apparently I need to setup
> the environment. Can any tapestry experts out there give me some advice on
> what I'm missing and where I should copy / paste from? I'm hoping to get a
> JSONObject with a "scripts" property that contains the scripts added via
> JavaScriptSupport.
>
> The service which does the magic is here
> https://github.com/uklance/tapestry-cometd/blob/master/src/main/java/org/lazan/t5/cometd/services/internal/ComponentJsonRendererImpl.java
>
> Cheers,
> Lance.
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Async-process-ComponentRequestHandler-and-JavaScriptSupport-tp5714401.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

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