Jahia in English > How to sort property...

0 (0 Good)
0 (0 Bad)

How to sort property referenced elements

by  thbaymet »  2015/12/06 00:09

Hi, I've the following structure on my JCR.

Name: componentName
Path: /path/to/component
ID: 1e86d193-40f2-41e6-b77b-da1332f5eb14
Type: int:myComponent
Mixins: []

Properties: hide

  • jcr:createdBy:  root
  • j:fullpath:  /path/to/component
  • jcr:versionHistory:  1e86d193-40f2-41e6-b77b-da1332f5eb14 (85e8f710-193e-4174-8ba1-cabb89763de8)
  • elements: 
    • ref12 (85700b86-6990-4108-8eea-db0a529d9ddb)
    • ref15 (9dbe4d1c-c973-4dcc-b174-27abc4dd62b9)
    • ref18 (fc652572-1508-403c-9590-42f0b0676ea8)
    • ref48 (ff4e57f7-62d5-4d58-b974-b72c7541c0eb)
    • ref69 (cdb9ab3d-2a65-46aa-a846-49739c103d25)
  • jcr:lastModified:  2015-12-05 23:14:22

I'm able to get the referenced (weakrefernces) elements one by one with the following code:

<jcr:node var="myComponent" uuid="${componentUUID}"/>
<c:forEach items="${myComponent.properties.elements}" var="element">
    <jcr:nodeProperty node="${element.node}" name="jcr:title" var="title"/>

And each ref element has 

- orderNumber (long)

property which let me order the elements when I use a query (SELECT * from jnt:element as elements order by elements.orderNumber). However, I don't know how to order them before the loop when I took them from a propery.

Please, help me if you know how can I sort them without using the query.

 

  • How to sort property referenced elements
    2015/12/06 00:10

    thbaymet <p>Hi, I&#39;ve the following structure on my JCR.</p> <p style="color: rgb(54, 57, 61); font-family: Arial, Helvetica, sans-serif; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20.48px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><strong>Name: </strong>componentName<br /> <strong>Path:&nbsp;</strong>/path/to/component<br /> <strong>ID:&nbsp;</strong>1e86d193-40f2-41e6-b77b-da1332f5eb14<br /> <strong>Type:&nbsp;</strong>int:myComponent<br /> <strong>Mixins:&nbsp;</strong>[]</p> <p style="color: rgb(54, 57, 61); font-family: Arial, Helvetica, sans-serif; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20.48px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><strong>Properties:&nbsp;</strong>hide</p> <ul style="color: rgb(54, 57, 61); font-family: Arial, Helvetica, sans-serif; font-size: 12.8px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20.48px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"> <li><strong>jcr:createdBy:&nbsp;</strong> root</li> <li><strong>j:fullpath:&nbsp;</strong> /path/to/component</li> <li><strong>jcr:versionHistory:&nbsp;</strong> 1e86d193-40f2-41e6-b77b-da1332f5eb14 (85e8f710-193e-4174-8ba1-cabb89763de8)</li> <li><strong>elements:&nbsp;</strong> <ul> <li>ref12 (85700b86-6990-4108-8eea-db0a529d9ddb)</li> <li>ref15 (9dbe4d1c-c973-4dcc-b174-27abc4dd62b9)</li> <li>ref18 (fc652572-1508-403c-9590-42f0b0676ea8)</li> <li>ref48 (ff4e57f7-62d5-4d58-b974-b72c7541c0eb)</li> <li>ref69 (cdb9ab3d-2a65-46aa-a846-49739c103d25)</li> </ul> </li> <li><strong>jcr:lastModified:&nbsp;</strong> 2015-12-05 23:14:22</li> </ul> <p>I&#39;m able to get the referenced (weakrefernces) elements one by one with the following code:</p> <pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier 10 Pitch';font-size:10,5pt;"> <span style="background-color:#232525;">&lt;</span><span style="color:#9876aa;background-color:#232525;font-weight:bold;">jcr</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">:node </span><span style="background-color:#232525;">var</span><span style="color:#a5c261;background-color:#232525;">=&quot;myComponent</span><span style="color:#a5c261;background-color:#232525;">&quot; </span><span style="background-color:#232525;">uuid</span><span style="color:#a5c261;background-color:#232525;">=&quot;</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">${</span><span style="background-color:#232525;">componentUUID</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">}</span><span style="color:#a5c261;background-color:#232525;">&quot;</span><span style="background-color:#232525;">/&gt;</span> <span style="background-color:#232525;">&lt;</span><span style="color:#9876aa;background-color:#232525;font-weight:bold;">c</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">:forEach </span><span style="background-color:#232525;">items</span><span style="color:#a5c261;background-color:#232525;">=&quot;</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">${</span><span style="background-color:#232525;">myComponent.properties.elements</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">}</span><span style="color:#a5c261;background-color:#232525;">&quot; </span><span style="background-color:#232525;">var</span><span style="color:#a5c261;background-color:#232525;">=&quot;element</span><span style="color:#a5c261;background-color:#232525;">&quot;</span><span style="background-color:#232525;">&gt;</span> <span style="background-color:#232525;">&lt;</span><span style="color:#9876aa;background-color:#232525;font-weight:bold;">jcr</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">:nodeProperty </span><span style="background-color:#232525;">node</span><span style="color:#a5c261;background-color:#232525;">=&quot;</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">${</span><span style="background-color:#232525;">element.node</span><span style="color:#cc7832;background-color:#232525;font-weight:bold;">}</span><span style="color:#a5c261;background-color:#232525;">&quot; </span><span style="background-color:#232525;">name</span><span style="color:#a5c261;background-color:#232525;">=&quot;</span><span style="color:#6a8759;background-color:#232525;">jcr:title</span><span style="color:#a5c261;background-color:#232525;">&quot; </span><span style="background-color:#232525;">var</span><span style="color:#a5c261;background-color:#232525;">=&quot;</span><span style="color:#6a8759;background-color:#232525;">title</span><span style="color:#a5c261;background-color:#232525;">&quot;</span><span style="background-color:#232525;">/&gt;</span></pre> <p>And each ref element has&nbsp;</p> <pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier 10 Pitch';font-size:10,5pt;"> - orderNumber (long)</pre> <p>property which let me order the elements when I use a query (SELECT * from jnt:element as elements order by elements.orderNumber). However, I don&#39;t know how to order them before the loop when I took them from a propery.</p> <p>Please, help me if you know how can I sort them without using the query.</p> <p>&nbsp;</p>

  • Number of messages  19
    Registration date Dec 6, 2015
    0 (0 Good)
    0 (0 Bad)

    Re: How to sort property referenced elements

    by  vk »  2016/01/07 18:59

    I had the same issue but solved it using the following code 

    <jcr:sql var="result" sql="SELECT * from [jnt:element] as elements order by elements.[orderNumber]"/>

    <c:forEach items="${result.nodes}" var="node" varStatus="status">
                       <jcr:node var="item" path="${node.path}"/>

    </c:forEach>

    Thanks,

    vk

    vk
    Number of messages  5
    Not registered
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page