Just further to this, here is the utility service I use to wrap JS calls from any context (which helps leverage re-usable code).

ie using this avoids having to change between AjaxResponseRenderer and JavaScriptSupport depending on the context (XHR/phase).

public class JavaScriptHelperImpl implements JavaScriptHelper
{
    @Inject
    private Environment env;
    @Inject
    private AjaxResponseRenderer ajaxResponseRenderer;
    @Inject
    private Request request;
    @Inject
    private JavaScriptSupport jsSupport;

    @Override
public void addScript(final InitializationPriority priority, final String format, final Object... args)
    {
        if (!request.isXHR()
// test environment for existence of JS support - ie only use AjaxResponseRenderer if xhr AND not render phase
                || env.peek(JavaScriptSupport.class) != null)
        {
            jsSupport.addScript(priority, format, args);
            return;
        }

        ajaxResponseRenderer.addCallback(new JavaScriptCallback()
        {
            @Override
            public void run(JavaScriptSupport javascriptSupport)
            {
                javascriptSupport.addScript(priority, format, args);
            }
        });
    }
}

On 16/07/2012 8:11 AM, Paul Stanton wrote:
As Lance said, you need to use JavascriptSupport when preparing a non-ajax response, and AjaxResponseRenderer when you are...

if (request.isXHR())
{
    // use AjaxResponseRenderer
}
else
{
    // use JavascriptSupport
}

however if the bug (https://issues.apache.org/jira/browse/TAP5-1870 ) affects your case too then afterrender is not being triggered automatically by the framework and you need to execute the method (call set yourself) from within your component event handler...

hope that helps, paul.

On 15/07/2012 11:17 PM, bhorvat wrote:
Hi Paul,

Hm... yea this appears to be the same problem that I am having. The set
method gets called but the run part doesn't. In other words the methods is called and the callback is added to the AjaxResponseRenderer but it is never
triggered (the add script part in the run method that is)

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Injection-javascript-code-AjaxResponseRenderer-vs-JavaScriptSupport-tp5714464p5714469.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
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

Reply via email to