Saturday, November 17, 2012

Ajax Fundamentals

Instructions for no-frills AJAX.

1) Create anchor tag and add ajax-target which points to the location where you want the result displayed.
2) Create the target tag.
3) In workflow, create and return an AjaxResponse using static or dynamic content.
4) If your response includes a <c:document/> tag, make sure you add the document onto the AjaxResponse so any changes to the document are visible.  Otherwise you'll be looking at the cached document.

In the page/fragment:

<c:a action="yourAction" ajax-target="yourTarget">click me</c:a>
<br/>
<div id="yourTarget"></div>


In workflow
return c.createAjaxResponse(c.getPal().getAjaxFragment("yourContent"),true);


or if you're dealing with a document update

var pal=c.getPal();
var doc = packet.getFirstDocument();
var frag=pal.getAjaxFragment("yourContentWithDocumentTag");
var response=c.createAjaxResponse(frag,true);
response.addDocument(doc);
return response;

No comments:

Post a Comment