You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by vkrejcirik <vk...@gmail.com> on 2009/08/03 20:59:03 UTC

JQuery and Apache SLing

Hi,
I need to search text in nodes in JCR repository. I can use JQuery. I 
have this code, but it doesn't work.
Do you have any idea, pls?

 <form action="search.html" method="GET">
      <input type="submit" value="Search"/>
       <textarea id="searchCriteria" rows="1" cols="50"></textarea>
  </form>

<% 
   var queryManager = 
currentNode.getSession().getWorkspace().getQueryManager();
 
   if(request.getParameter('searchCriteria')) {
       var query = 
queryManager.createQuery("/servicemix/message_flows[jcr:contains(., 
'"+request.getParameter("searchCriteria")+"')] order by @created 
descending", "xpath");
   }
    else {
       var query = queryManager.createQuery("/servicemix/message_flows/* 
order by @created descending", "xpath");
   }

   var result = query.execute().getNodes();
%>

Thanks a lot.

-- 
/**************************************/
Best regards / S pozdravem
Vladislav Krejčiřík

http://www.vkrejcirik.info


Re: JQuery and Apache SLing

Posted by Alexander Klimetschek <ak...@day.com>.
2009/8/3 vkrejcirik <vk...@gmail.com>:
> I need to search text in nodes in JCR repository. I can use JQuery.

The query language you are talking about is called "XPath" (JCR 1.0
specifies a subset of XPath). JQuery is a client-side/browser-based
Javascript library and has nothing to do with JCR or Sling.

Otherwise Eric is right (but use "/jcr:root" and not "*/jcr:root*"
;-)) Whenever you have an absolute JCR path at the beginning of the
XPath, you have to start it with /jcr:root. If you do something like
"//element(*, nt:file)", you don't need the jcr:root prefix.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: JQuery and Apache SLing

Posted by Eric Norman <er...@gmail.com>.
Try prepending "/jcr:root" on the front of your xpath query:

Like this:

 if(request.getParameter('searchCriteria')) {
     var query =
queryManager.createQuery("*/jcr:root*/servicemix/message_flows[jcr:contains(.,
'"+request.getParameter("searchCriteria")+"')] order by @created
descending", "xpath");
 }
  else {
     var query =
queryManager.createQuery("*/jcr:root*/servicemix/message_flows/*
order by @created descending", "xpath");
 }



2009/8/3 vkrejcirik <vk...@gmail.com>

> Hi,
> I need to search text in nodes in JCR repository. I can use JQuery. I have
> this code, but it doesn't work.
> Do you have any idea, pls?
>
> <form action="search.html" method="GET">
>     <input type="submit" value="Search"/>
>      <textarea id="searchCriteria" rows="1" cols="50"></textarea>
>  </form>
>
> <%  var queryManager =
> currentNode.getSession().getWorkspace().getQueryManager();
>
>  if(request.getParameter('searchCriteria')) {
>      var query =
> queryManager.createQuery("/servicemix/message_flows[jcr:contains(.,
> '"+request.getParameter("searchCriteria")+"')] order by @created
> descending", "xpath");
>  }
>   else {
>      var query = queryManager.createQuery("/servicemix/message_flows/*
> order by @created descending", "xpath");
>  }
>
>  var result = query.execute().getNodes();
> %>
>
> Thanks a lot.
>
> --
> /**************************************/
> Best regards / S pozdravem
> Vladislav Krejčiřík
>
> http://www.vkrejcirik.info
>
>