Hi Jason

I take it the idea is to strictly modularize on a CQ component level? While
there is some support for placing java files in the JCR and use them as
servlets for specific resources, this approach is somewhat exotic and you're
better of providing application code  - such as models - in OSGi bundles.
This is much better in terms of separation of layers and concerns, and
allows you to use all the OSGi goodness Felix provides, such as SCR
(http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-pl
ugin/scr-annotations.html) as well as any of the following solutions:

1.) The #1 way to provide specific models for resource in Sling is to use an
AdapterFactory so you can .adaptTo(SpecificModel.class) from a resource,
e.g. in a view, taglib, servlet and the like.
(http://sling.apache.org/documentation/the-sling-engine/adapters.html)

2.) Nowadays, you can do so declaratively using Sling Models
(http://sling.apache.org/documentation/bundles/models.html). This also gives
you Resource - to - model mapping, i.e. mapping properties and resources
onto a POJO java model.

3.) If you'd like to leverage google guice, you can use Slice from cognifide
(http://www.cognifide.com/blogs/cq/make-your-cq-life-easier-with-slice/).
This will also support .adaptTo and provides resource to model mapping.

4.) Finally, there is NEBA (http://neba.io), which gives you .adaptTo +
resource to model mapping and Spring MVC plus some more features. I'm a bit
biased towards that one - since I am NEBA's lead developer ;-)


Kind regards,
Olaf



-----Original Message-----
From: Jason Bailey [mailto:jason.bai...@sas.com] 
Sent: Mittwoch, 16. Juli 2014 21:07
To: users@sling.apache.org
Subject: adding java classes into the jcr

We're using CQ5 pretty extensively for our external web presence and I'm in
the process of evaluating Sling for a wider range of use cases internally.

One of the questions that comes up on a regular basis is whether we are able
to define a java object alongside the JSP when we are creating a widget. So
that we can potentially implement a very specific business logic and have it
co-located with the presentation logic.   There seems to be support in Sling
for compiling java classes located in the JCR, but there's a lack of clarity
on when/how that occurs.

Any information would be appreciated.

-Jason

Reply via email to