Jaxrs-scalate is a project mainly written in SCALA and JAVA, based on the Apache-2.0 license.
JAX-RS Scalate view provider for POJO models
This package provides a JAX-RS provider to allow Scalate views to be used to render POJO models as HTML pages.
The source for the JAX-RS Scalate provider can be found on GitHub. You can get a copy of the source by cloning the Git repository:
git clone git://github.com/mikepb/jaxrs-scalate.git
The package is built using Maven:
mvn package
The JAX-RS Scalate provider requires a JAX-RS engine. Here is a simple Resteasy web.xml snippet:
<web-app>
...
<filter>
<filter-name>Resteasy</filter-name>
<filter-class>org.jboss.resteasy.plugins.server.servlet.FilterDispatcher</filter-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>MyApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Resteasy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
</web-app>
Implementation-specific instructions are available for:
The ScalateProvider
JAX-RS provider is configured via the Application
interface:
import _root_.com.mikepb.jaxrs.scalate.JaxrsScalateProvider
class MyApplication extends Application with JaxrsScalateApplication {
override def getClasses: java.util.Set[Class[_]] = {
val classes = new HashSet[AnyRef]
classes.add(classOf[LandingPageResource])
classes.addAll(super.getClasses)
classes
}
}
More information is available from the JAX-RS JavaDocs.
Implementation-specific instructions are available for:
To render POJO objects using Scalate views, use the JAX-RS @Produces
annotation to tell the JAX-RS implementation that you want the returned POJO
should be rendered using the Scalate provider.
The JAX-RS API revolves around resources. LandingPageResource.scala
is an
example resource that displays a message when loading the root URL /
:
import javax.ws.rs._
@Path("/")
@Produces(Array("text/html"))
class LandingPageResource {
@GET
def index = Message("Hello World!")
}
case class Message(message: String)
The Scalate view Message.index.jade
for Message
:
p= message
To use a view other than "index", use the @ViewName
annotation to provide
the view name:
import javax.ws.rs._
import com.mikepb.jaxrs.scalate.ViewName
@Path("/")
@Produces(Array("text/html"))
@ViewName("custom")
class LandingPageResource {
@GET
def index = this
}
The Scalate view LandingPageResource.custom.jade
for LandingPageResource
:
:markdown
This is a custom view!
See the Scalate documentation for more information about how views work.