user3503093
user3503093

Reputation: 77

Add pagelink via ajax in tapestry

After an ajax call, I want to inject some element (list) in page. For each element of the list, I want to attach t:pagelink. I use PrototypeJs as js framework. Have you any idea? I have already test the code below but doesn't work (it not render the t:pagelink)

new Ajax.Request('my_service_url', {
  onSuccess: function(response) {
	response.responseJSON.data.each(function(item){
		var li = '<li>'+
		'<span>'+item.title+'</span>'+
		'<t:pagelink page="examples/navigation/PageLinks2">'+item.link+'</t:pagelink>'+
		'</li>';
		$('mylist').insert(li);
	});
  }
});

Upvotes: 0

Views: 131

Answers (2)

Markus Fischer
Markus Fischer

Reputation: 1366

This does not work with Tapestry, as Lance Java pointed out, because the Javascript snippet is executed on the client. The client can't submit the <t:pagelink> tag to Tapestry for interpretation.

What you need to do instead is use the Ajax semantic of Tapestry, in particular the Zone component. <t:zone>...</t:zone> defines a section of your HTML document which will be replaced with a new version, rendered from .tml to html by Tapestry.

So in your <t:zone>, add <t:pagelink>'s as needed, probably dynamically, based on some condition or in some loop (i.e. with <t:if> or <t:loop> tags). Then, use some mechanism to send an AJAX event back to Tapestry. One simple option would be to use <t:actionlink zone="[ID of your zone]">.

See here for more info on Zones.

Upvotes: 0

user3503093
user3503093

Reputation: 77

Thanks for your reply but I've found the solution. Just use processReply and it's ok. Indeed, the response needed a bit modification.

Upvotes: 0

Related Questions