You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by nquirynen <na...@pensionarchitects.be> on 2012/11/05 14:01:52 UTC

ajaxResponseRenderer in event

Hi,

I have a problem with executing some javascript after an ajax call to a
tapestry event.

*Test.class*
public class Test {
	
	@Inject
	private ComponentResources componentResources;
	
	@Inject
	private AjaxResponseRenderer ajaxResponseRenderer;
	
	@Inject 
	private JavaScriptSupport javaScriptSupport;
	
	public String getEventLink() {
		return componentResources.createEventLink("alert").toURI();
	}
	
	@BeginRender
	void beginRender() {
		javaScriptSupport.addScript("$.get('%s');", getEventLink());
	}
	
	void onAlert() {
		ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
			
			@Override
			public void run(JavaScriptSupport javascriptSupport) {
				javascriptSupport.addScript("window.alert('test');");				
			}
		});
	}
}

So following steps take place:

1) in beginRender() I add a ajax call to the event with JavascriptSupport
2) onAlert() is called and here I try to add a javascript callback with
AjaxResponseRenderer
   
in the response of the request I see the following:

{
  "inits" : [
    {
      "evalScript" : [
        "window.alert('test');"
      ]
    }
  ]
}

But this javascript never fires.


I don't understand why, I'm probably missing something here, so any input
would be helpful.

ps: I know the code doesn't make sense, it's just a simple example to show
where I'm stuck

Nathan






--
View this message in context: http://tapestry.1045711.n5.nabble.com/ajaxResponseRenderer-in-event-tp5717654.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: ajaxResponseRenderer in event

Posted by Howard Lewis Ship <hl...@gmail.com>.
You'll like this in 5.4 better; the page initialization JSON is buried in a
new key and handled automatically for you; it can now piggyback on any JSON
Object response, not just the standard partial page render response.


On Mon, Nov 5, 2012 at 5:09 AM, Charlouze <me...@charlouze.com> wrote:

> Can you send the client code that handle the request ? IMHO, I think that
> you forget to process json response, I have already done that mistake a lot
> of time.
>
> 2012/11/5 nquirynen <na...@pensionarchitects.be>
>
> > Hi,
> >
> > I have a problem with executing some javascript after an ajax call to a
> > tapestry event.
> >
> > *Test.class*
> > public class Test {
> >
> >         @Inject
> >         private ComponentResources componentResources;
> >
> >         @Inject
> >         private AjaxResponseRenderer ajaxResponseRenderer;
> >
> >         @Inject
> >         private JavaScriptSupport javaScriptSupport;
> >
> >         public String getEventLink() {
> >                 return
> componentResources.createEventLink("alert").toURI();
> >         }
> >
> >         @BeginRender
> >         void beginRender() {
> >                 javaScriptSupport.addScript("$.get('%s');",
> > getEventLink());
> >         }
> >
> >         void onAlert() {
> >                 ajaxResponseRenderer.addCallback(new
> JavaScriptCallback() {
> >
> >                         @Override
> >                         public void run(JavaScriptSupport
> > javascriptSupport) {
> >
> > javascriptSupport.addScript("window.alert('test');");
> >                         }
> >                 });
> >         }
> > }
> >
> > So following steps take place:
> >
> > 1) in beginRender() I add a ajax call to the event with JavascriptSupport
> > 2) onAlert() is called and here I try to add a javascript callback with
> > AjaxResponseRenderer
> >
> > in the response of the request I see the following:
> >
> > {
> >   "inits" : [
> >     {
> >       "evalScript" : [
> >         "window.alert('test');"
> >       ]
> >     }
> >   ]
> > }
> >
> > But this javascript never fires.
> >
> >
> > I don't understand why, I'm probably missing something here, so any input
> > would be helpful.
> >
> > ps: I know the code doesn't make sense, it's just a simple example to
> show
> > where I'm stuck
> >
> > Nathan
> >
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://tapestry.1045711.n5.nabble.com/ajaxResponseRenderer-in-event-tp5717654.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
> >
> >
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Re: ajaxResponseRenderer in event

Posted by Charlouze <me...@charlouze.com>.
If you can't use the zonemanager.processReply function defined by tapestry,
you will have to handle the response yourself. You really should take a
look at the tapestry.js file to  see what this function does.

2012/11/5 nquirynen <na...@pensionarchitects.be>

> I have no client code, so yea that's why it probably doesn't work...
>
> First my code was like this:
> I had a callback function on the ajax request in my .tml:
>
>
>
> which works.
>
> But I wanted to remove javascript from my .tml files and while doing this I
> thought AjaxResponseRenderer.addCallback would actually run this script
> automatically.
>
> So this means I still have to handle the response myself?
>
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/ajaxResponseRenderer-in-event-tp5717654p5717658.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: ajaxResponseRenderer in event

Posted by nquirynen <na...@pensionarchitects.be>.
I have no client code, so yea that's why it probably doesn't work...

First my code was like this:
I had a callback function on the ajax request in my .tml:



which works.

But I wanted to remove javascript from my .tml files and while doing this I
thought AjaxResponseRenderer.addCallback would actually run this script
automatically.

So this means I still have to handle the response myself?





--
View this message in context: http://tapestry.1045711.n5.nabble.com/ajaxResponseRenderer-in-event-tp5717654p5717658.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: ajaxResponseRenderer in event

Posted by Charlouze <me...@charlouze.com>.
Can you send the client code that handle the request ? IMHO, I think that
you forget to process json response, I have already done that mistake a lot
of time.

2012/11/5 nquirynen <na...@pensionarchitects.be>

> Hi,
>
> I have a problem with executing some javascript after an ajax call to a
> tapestry event.
>
> *Test.class*
> public class Test {
>
>         @Inject
>         private ComponentResources componentResources;
>
>         @Inject
>         private AjaxResponseRenderer ajaxResponseRenderer;
>
>         @Inject
>         private JavaScriptSupport javaScriptSupport;
>
>         public String getEventLink() {
>                 return componentResources.createEventLink("alert").toURI();
>         }
>
>         @BeginRender
>         void beginRender() {
>                 javaScriptSupport.addScript("$.get('%s');",
> getEventLink());
>         }
>
>         void onAlert() {
>                 ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
>
>                         @Override
>                         public void run(JavaScriptSupport
> javascriptSupport) {
>
> javascriptSupport.addScript("window.alert('test');");
>                         }
>                 });
>         }
> }
>
> So following steps take place:
>
> 1) in beginRender() I add a ajax call to the event with JavascriptSupport
> 2) onAlert() is called and here I try to add a javascript callback with
> AjaxResponseRenderer
>
> in the response of the request I see the following:
>
> {
>   "inits" : [
>     {
>       "evalScript" : [
>         "window.alert('test');"
>       ]
>     }
>   ]
> }
>
> But this javascript never fires.
>
>
> I don't understand why, I'm probably missing something here, so any input
> would be helpful.
>
> ps: I know the code doesn't make sense, it's just a simple example to show
> where I'm stuck
>
> Nathan
>
>
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/ajaxResponseRenderer-in-event-tp5717654.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: ajaxResponseRenderer in event

Posted by Alex Kotchnev <ak...@gmail.com>.
There was a bug in tapestry-jquery not too long ago that wasn't processing
the scripts on ajax events - make sure that you're on the latest
tapestry-jquery version.

Cheers - Alex K

On Mon, Nov 5, 2012 at 9:28 AM, nquirynen <na...@pensionarchitects.be>wrote:

> I think I found it:
>
> *$.tapestry.utils.loadScriptsInReply(r);*
>
> I put this in the ajax request callback function and looks like its working
> now. So now my Test page code looks like:
>
> public class Test {
>
>         @Inject
>         private ComponentResources componentResources;
>
>         @Inject
>         private AjaxResponseRenderer ajaxResponseRenderer;
>
>         @Inject
>         private JavaScriptSupport javaScriptSupport;
>
>         public String getEventLink() {
>                 return componentResources.createEventLink("alert").toURI();
>         }
>
>         @BeginRender
>         void beginRender() {
>                 javaScriptSupport.addScript("$.get('%s',
> function(r){$.tapestry.utils.loadScriptsInReply(r);});", getEventLink());
>         }
>
>         void onAlert() {
>                 ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
>
>                         @Override
>                         public void run(JavaScriptSupport
> javascriptSupport) {
>
> javascriptSupport.addScript("window.alert('test');");
>                         }
>                 });
>         }
> }
>
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/ajaxResponseRenderer-in-event-tp5717654p5717659.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: ajaxResponseRenderer in event

Posted by nquirynen <na...@pensionarchitects.be>.
I think I found it:

*$.tapestry.utils.loadScriptsInReply(r);*

I put this in the ajax request callback function and looks like its working
now. So now my Test page code looks like:

public class Test {
	
	@Inject
	private ComponentResources componentResources;
	
	@Inject
	private AjaxResponseRenderer ajaxResponseRenderer;
	
	@Inject 
	private JavaScriptSupport javaScriptSupport;
	
	public String getEventLink() {
		return componentResources.createEventLink("alert").toURI();
	}
	
	@BeginRender
	void beginRender() {
		javaScriptSupport.addScript("$.get('%s',
function(r){$.tapestry.utils.loadScriptsInReply(r);});", getEventLink());
	}
	
	void onAlert() {
		ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
			
			@Override
			public void run(JavaScriptSupport javascriptSupport) {
				javascriptSupport.addScript("window.alert('test');");				
			}
		});
	}
}





--
View this message in context: http://tapestry.1045711.n5.nabble.com/ajaxResponseRenderer-in-event-tp5717654p5717659.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: ajaxResponseRenderer in event

Posted by Lance Java <la...@googlemail.com>.
You are using $.get() to get an eventlink URL and you are doing nothing with
the response. The default tapestry implementation (prototype) has a
ZoneManager.processReply() which is used to process an event response. 

It looks like you are using tapestry-jquery so you will need to find the
equivalent functionality in that module.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/ajaxResponseRenderer-in-event-tp5717654p5717656.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