Developers: Paul Sandoz
Status: ongoing
Jersey has support for pluggable view templates with a JSP implementation. See the bookstore example in the Jersey distribution for an example of how this works.
The API and implementation can be improved so that view templates can be picked up dynamically (no need to require the of use annotations) and the runtime model of a resource class modified accordingly.
Investigate how to improve the API/SPI to better support model/view/controller separation. The following presents an example of how views can be better connected to HTTP methods:
/**
* View templates are placed in a directory that is the fully qualified
* Class name of a resource class suitably converted to a file system path,
* <class>.
* The directory is relative to some base directory, <base>
*
* The type of view template is specified by the suffix <t>, for example "jsp",
* "vel" (for velocity) "wick" (for wicket) etc.
*
* MIME media types may also be specified by a suffix, for example,
* "html" "xhtml" "xml" after <t>
*
* The HTTP method may be declared before the suffix <t>.
*/
public class MyResource {
/**
* Look for template <base>/<class>/index.<t> if not found
* look for template <base>/<class>/index.get.<t>
*/
@View
@GET
public String get() {
return "get-model";
}
/**
* Look for template <base>/<class>/index.post.<t>
*/
@View
@POST
public String post() {
return "post-model";
}
/**
* Look for template <base>/<class>/sub.<t> if not found
* look for template <base>/<class>/sub.get.<t>
*
* Uri template is required to be a path segment with no template values.
*
* return the resource class as the model, so resource class =
* controller+model
*/
@View
@Path("sub")
@GET
public MyResource getSub() {
return this;
}
/**
* Look for template <base>/<class>/sub.post.<t>
*/
@View
@Path("sub")
@POST
public String postSub() {
return "post-sub-model";
}
/**
* Look for an explicit template named "subEdit" at
* <base>/<class>/subEdit.<t>
*/
@View("subEdit")
@POST("subEdit")
@POST
public String postSubEdit() {
return "post-sub-edit-model";
}
}