I'm wondering what manual I missed and I'm not sure how to ask the question so I'll make it as open-ended as I can....
In LiveSite Display Services what is the difference between a .page address and a .ajax address?
A URL ending in .page asks LSDS to render that full page, and has the format
http://server:1776/mysite/some-folder/hello.page
Conversely, the AJAX request asks for the unrendered data associated with a particular component on a particular page. The goal is usually to re-evaluate an External call with a new set of parameters. It has the format
http://server:1776/mysite/some-folder/hello/12355123513.ajax
where the magic number is the component ID of a component on hello.page
The ajax request returns raw XML that has not been rendered through XSL. The concept is that you would have javascript pull the data and then render it in some way. In particular, it can update any part of the page, not just the div belonging to the component it queried. The execution is a bit weird though, as it usually means you'd have to write your rendering logic twice (once in XSL, once in JS). However, it would be one way to do such things as predictive type-ahead in a form field.
That is exactly what I was looking for - follow up...
Is there an OOTB way to get LSDS to return JUST a single component's generated output?
When you say generated, do you mean transformed by the component XSL?
When LSDS returns a page it adds a ton of "****" to the page including html, body, meta, script, div... tags. I would like to get back just what a single component generates.
So if my XSL for a component generates (is transformed into) nothing more than an <img...> tag, that's all I want to get back.
For example:
Component:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<img src="$URL_PREFIX{/Properties/Data/Datum[@Name='Image']}"/>
</xsl:template>
</xsl:stylesheet>
Result returned:
<img src="/myimage.jpg"/>
The short answer is 'no', or at least not cleanly.
You can kinda sorta achieve this with the LiveSite tag library (aka embedded livesite) but it's built a bit weird. In part, it would render a whole page and then use string replacement to cut out the parts that aren't the component you asked for.
That's what I expected.
What we ended up doing was to create a new page template layout that didn't add anything to the page. This is being used to return JSON and XML results.
It works well, I was just hoping there was an OOTB solution.
An alternative is to use the AjaxOutput with a separate method an generate the entire response yourself.
The class/method called by AjaxOutput does not require a Dom4J Document returned, you can just write whatever you want to the HTTP response.
I use this method to generate alternative forms for a calendar component I created - eg. JSON and iCAL formats.
Wasn't sure what @Zaarin was talking about, so I did some digging and found the following.
The default behaviour of a component for which the AJAX output has not been defined is to output the unrendered data of the component, as I specified above. However, as Zaarin is saying, you can define an AjaxOutput handler for your component in the Component XML portion (same place you'd define an External) in format:
<Data> <AjaxOutput Object="com.mycompany.MyAjaxHandler" Method="getAjaxContent" Scope="local" /> <!-- ... --></Data>
The method signature required would be "public void getAjaxContent(RequestContext context)". The return value is ignored (you might be able to use void instead of Object?). In this case, your handler is responsible for printing the HTTP response body to the web client, via context.getResponse(). Thus, you can either render your component via something like ((RuntimeComponent)context.getThisComponent()).transform() or you can return something entirely different (like a JSON feed).
rpoulin, yes, I just use void for the method signature.