|
Nuxeo ECM Projects 5.4.3-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.nuxeo.ecm.webengine.model.impl.AbstractResource<ResourceTypeImpl> org.nuxeo.ecm.webengine.model.impl.DefaultObject org.nuxeo.ecm.webengine.samples.HelloObject org.nuxeo.ecm.webengine.samples.TemplatingObject
public class TemplatingObject
Templates sample. This demonstrates how to use template files to build client responses. JAX-RS provides a flexible mechanism to send responses based on the mime type that the client expects. To send a response to the client you simply return the Object you want as the response. JAX-RS engines will usually know how to render common Java objects like String, InputStream, File etc. If you need to output specific objects you need to register a custom MessageBodyWriter class. In JAX-RS you are not able to modify the HttpServletResponse object directly from a resource method. (add headers, cookies etc) Anything you may want to output must be returned from the resource method back to JAX-RS engine, and the engine will output it for you. This is a very good thing, even if for some people this approach may seem strange. You may ask yourself, ok cool, The response rendering is pretty well separated from the resource logic. But how can I modify response headers? In that case you must return a javax.ws.rs.Response that may be used to customize your response headers.
WebEngine is adding a new type of response objects: templates. Templates are freemarker based templates that can be used to render your objects depending on the request context. WebEngine is adding some cool extensions to freemarker templates that let you build your web site in a modular fashion. These extensions are called blocks. Blocks are dynamic template parts that can be extended or replaced using derived blocks. Using blocks, you can write a base template that may define the site layout (using blocks containing empty or generic content) and then write final skins for your layout by extending the base template and redefining blocks you are interested in. See the skin directory for template examples.
Templates are stored in files under the skin directory. Templates are always resolved relative to the skin directory, even if you are using absolute paths. The following variables are accessible from a template when rendered at rendering time:
Context
- the WebContext instance
Engine
- the WebEngine instance
This
- the target Web Object.
Root
- the root WebObject.
Document
- the target Document if any otherwise null.
Session
- the Repository Session. (aka Core Session)
basePath
- the request base path (context path + servlet path)
Constructor Summary | |
---|---|
TemplatingObject()
|
Method Summary | |
---|---|
Response |
doRedirect(String path)
Example of using redirect. |
Object |
getIndex1()
Return the template index.ftl from 'skin' directory |
Object |
getIndex1(String name)
Inject the variable 'name' in the template context and then return the template. |
Object |
getIndex2()
Render the index2 template |
Methods inherited from class org.nuxeo.ecm.webengine.samples.HelloObject |
---|
doGet, doGet |
Methods inherited from class org.nuxeo.ecm.webengine.model.impl.DefaultObject |
---|
disptachAdapter, isAdapter |
Methods inherited from class org.nuxeo.ecm.webengine.model.impl.AbstractResource |
---|
checkGuard, dispose, getActiveAdapter, getAdapter, getContext, getFacets, getLinks, getModule, getName, getNext, getNextSegment, getPath, getPrevious, getTemplate, getTrailingPath, getType, getURL, getView, hasFacet, initialize, isInstanceOf, isRoot, newAdapter, newObject, redirect, setNext, setPrevious, setRoot, toString |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TemplatingObject()
Method Detail |
---|
public Object getIndex1()
public Object getIndex1(String name)
public Object getIndex2()
public Response doRedirect(String path)
|
Nuxeo ECM Projects 5.4.3-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |