Hi Tobias,

How would you do this using JSTL?

Here is the test case I tried:
Create a file called html.jsp
--------------------------------------------------------------------------------------------


<[EMAIL PROTECTED] import="org.apache.sling.api.resource.ValueMap" %>
<[EMAIL PROTECTED] prefix="sling" 
uri="http://sling.apache.org/taglibs/sling/1.0"; %>
<[EMAIL PROTECTED] prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
<sling:defineObjects />
<%
  request.setAttribute("example", "hello world");
  pageContext.setAttribute("vm", resource.adaptTo(ValueMap.class));
%>
<html>
  <body>

    <h1>Demo using scriptlet</h1>
    <%= ((ValueMap) resource.adaptTo(ValueMap.class)).get("myref") %>



    <h1>Demo using JSTL</h1>
    <c:out value="${vm.myref}"/>


    <h1>Demo using evalProperty</h1>
    <sling:evalProperty property="myref"/>

  </body>
</html>

--------------------------------------------------------------------------------------------


Use Curl to set everything up:


curl -X MKCOL http://admin:[EMAIL PROTECTED]:8888/apps
curl -X MKCOL http://admin:[EMAIL PROTECTED]:8888/apps/foo
curl -X MKCOL http://admin:[EMAIL PROTECTED]:8888/apps/foo/bar
curl -X PUT -d @html.jsp http://admin:[EMAIL PROTECTED]
:8888/apps/foo/bar/html.jsp
curl -F"sling:resourceType=foo/bar" -F'myref=${example}'
http://admin:[EMAIL PROTECTED]:8888/content/mynode




Open browers at: http://mactrott:8888/content/mynode.html


Here is the result:
----------------------------------------------

Demo using scriptlet
${example}


Demo using JSTL
${example}


Demo using evalProperty
hello world

----------------------------------------------


Is there a better way of doing this so that JSTL will evaluate the property?



With regard to your point about direct DB access being "discouraged" this
isn't really an option for me, as I am looking at converting a large app and
pieces are going to need to come from the DB for some time.


However thats not really whats important to me, the goal I am trying to
achieve is to provide an extra level of indirection, whether that be use to
access a DB, a different branch of the JCR or some other data source.

The end goal is basically to be able to build a page using a GUI and just
drop to components on, one to load data from "somewhere" and one to visually
present it.

Thanks,
David






On Wed, Jul 23, 2008 at 2:09 AM, Tobias Bocanegra (JIRA) <[EMAIL 
PROTECTED]>wrote:

>
>    [
> https://issues.apache.org/jira/browse/SLING-577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12615924#action_12615924]
>
> Tobias Bocanegra commented on SLING-577:
> ----------------------------------------
>
> this is already possible when using JSTL and binding the properties (i.e
> resource.adaptTo(ValueMap.class) to the page context.
>
> directly accessing the DB is discouraged since all content should come from
> the repository.
>

Reply via email to