You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Ben Short <be...@benshort.co.uk> on 2009/11/23 12:20:19 UTC

JackRabbit + JSP/JSTL

Hi,

I'm investigating the use of jackrabbit for a project I am working on.
Considering the following examples accessing the jcr api in a jsp page is
pretty hard to read compared to the same thing using domain
objects. Admittedly the domain object version uses jstl rather than
scriptlets which IMO leads to cleaner code.

Is there any way to access the jcr api in a jsp file in a cleaner way or via
jstl?

Domain Object

<label for="${field.name}">
${field.labelText} <c:if test="${field.required}"><span
class="required">*</span></c:if>
<input type="text" id="${field.name}" name="${field.name}" size="30"
maxlength="${field.maxLength}" value="${param[field.name]}"/>
</label>


JCR

final String fieldName = fieldNode.getName();

%>
<label
for="<%=fieldName%>"><%=fieldNode.getProperty("label").getString()%><%if (
fieldNode.getProperty("required").getBoolean() ) {%><span
class="required">*</span><%}%>
     <input type="text" id="<%=fieldName%>" name="<%=fieldName%>" size="30"
maxlength="<%=fieldNode.getProperty("maxLength").getLong()%>"
value="<%=request.getParameter(fieldName)%>"/>
</label>
<%

Regards

Ben Short

Re: JackRabbit + JSP/JSTL

Posted by Ben Short <be...@benshort.co.uk>.
thanks for the replies.

some kind of taglib would be use full.

Ben

2009/11/23 Rakesh Vidyadharan <ra...@sptci.com>

>
> On 23 Nov 2009, at 05:23, Torgeir Veimo wrote:
>
> > 2009/11/23 Ben Short <be...@benshort.co.uk>:
> >> Is there any way to access the jcr api in a jsp file in a cleaner way or
> via
> >> jstl?
> >
> > Maybe try this code;
> >
> >
> http://kenai.com/projects/jcrcms/sources/svn/content/trunk/src/app/com/sptci/cms/site/model/NodeBean.java?rev=17
> >
> > It wraps a node in an object which is easier to access.
> >
> > --
> > -Tor
>
> Version 18 returns the native types in the get method (including
> dereferencing node types).
>
> Rakesh

Re: JackRabbit + JSP/JSTL

Posted by Rakesh Vidyadharan <ra...@sptci.com>.
On 23 Nov 2009, at 05:23, Torgeir Veimo wrote:

> 2009/11/23 Ben Short <be...@benshort.co.uk>:
>> Is there any way to access the jcr api in a jsp file in a cleaner way or via
>> jstl?
> 
> Maybe try this code;
> 
> http://kenai.com/projects/jcrcms/sources/svn/content/trunk/src/app/com/sptci/cms/site/model/NodeBean.java?rev=17
> 
> It wraps a node in an object which is easier to access.
> 
> -- 
> -Tor

Version 18 returns the native types in the get method (including dereferencing node types).

Rakesh

Re: JackRabbit + JSP/JSTL

Posted by Torgeir Veimo <to...@netenviron.com>.
2009/11/23 Ben Short <be...@benshort.co.uk>:
> Is there any way to access the jcr api in a jsp file in a cleaner way or via
> jstl?

Maybe try this code;

http://kenai.com/projects/jcrcms/sources/svn/content/trunk/src/app/com/sptci/cms/site/model/NodeBean.java?rev=17

It wraps a node in an object which is easier to access.

-- 
-Tor

Re: JackRabbit + JSP/JSTL

Posted by Alexander Klimetschek <ak...@day.com>.
On Mon, Nov 23, 2009 at 12:20, Ben Short <be...@benshort.co.uk> wrote:
> Is there any way to access the jcr api in a jsp file in a cleaner way or via
> jstl?

Not directly, but with a small helper such as the ValueMap [1] and its
JCR implementation [2] in Apache Sling.

You use it as follows:
ValueMap map = new JcrPropertyMap(node);
String foo = map.get("foobar", "default"); // using default values and
automatic types, in this case expecting a string property
Integer counter = map.get("counter", Integer.class); // converts to
int (jcr api) or returns null if not present

[1] http://svn.apache.org/repos/asf/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/ValueMap.java
[2] http://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrPropertyMap.java

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com