How to get node properties from path in a multifield | Community
Skip to main content
New Participant
Jul 19, 2017 6:27 AM UTC
Solved

How to get node properties from path in a multifield

I am using a multi field where pathfield is the input of the dialog....From this path i need to fetch its node properties to get its jcr:title,jcr:description......

Please help me ASAP.....

<%@ page import="org.apache.sling.commons.json.JSONObject" %>

<%@ page import="java.io.PrintWriter" %>

<%@include file="/libs/foundation/global.jsp" %>

<%@page session="false" %>

<div style="display: block; border-style: solid; border-width: 1px; margin: 10px; padding: 10px">

<b>Multi Field Sample Dashboard</b>

<br><br>

///Code for multifield

<%

    try

{

        String[] dashboards = { "iItems", "uItems" } ;

for(String dash : dashboards)

{

            Property property = null;

if (currentNode.hasProperty(dash))

{

property = currentNode.getProperty(dash);

}

if (property != null)

{

JSONObject obj = null;

Value[] values = null;

          if (property.isMultiple())

{

values = property.getValues();

}

else

{

values = new Value[1];

                    values[0] = property.getValue();

               }

                for (Value val : values)

{

obj = new JSONObject(val.getString());

%>

/////This is my code to convert path to node...

<%

    String componentPath = "<%=obj.get("path")%>/jcr:content"; //path to component

    Node node = resourceResolver.getResource(componentPath).adaptTo(Node.class);

    String title = node.getProperty("jcr:title").getString();

    String text = node.getProperty("jcr:primaryType").getString();

           %>

                   

<br><br>

<%

                    }

         

      } else {

%>

         

         

       

            <br><br>

<%

                }

   

    }

    }

catch (Exception e)

{

        e.printStackTrace(new PrintWriter(out));

 

  }

%>

</div>

After giving my code inside the loop ,,,the whole loop is getting error .what changes do i need to make in this code to get the path from dialog and fetch its node properties.........

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
zeeshanKhan0786
zeeshanKhan0786Accepted solution
Level 5
Jul 19, 2017 8:53 AM UTC

Hi praveen,

<%=<variable>%> so this tag is used for

  • Expression tag evaluates the expression placed in it.
  • It accesses the data stored in stored application.
  • It allows create expressions like arithmetic and logical.
  • It produces scriptless JSP page.

For more information https://www.guru99.com/jsp-elements.html

In this line

    String componentPath = "<%=obj.get("path")%>/jcr:content"; //path to component

without closing the script tag you are putting <%= ..%> this cause of problem their is no need of this.It make the syntax error in your code

Write in this way

String componentPath = obj.get("path") + "/jcr:content";

will work.

Try this and let me know this is Helpful

2 replies

zeeshanKhan0786
zeeshanKhan0786Accepted solution
Level 5
Jul 19, 2017 8:53 AM UTC

Hi praveen,

<%=<variable>%> so this tag is used for

  • Expression tag evaluates the expression placed in it.
  • It accesses the data stored in stored application.
  • It allows create expressions like arithmetic and logical.
  • It produces scriptless JSP page.

For more information https://www.guru99.com/jsp-elements.html

In this line

    String componentPath = "<%=obj.get("path")%>/jcr:content"; //path to component

without closing the script tag you are putting <%= ..%> this cause of problem their is no need of this.It make the syntax error in your code

Write in this way

String componentPath = obj.get("path") + "/jcr:content";

will work.

Try this and let me know this is Helpful

Translate
viveksachdeva
New Participant
Jul 19, 2017 8:46 AM UTC

Need more details...

-Which version of AEM are you working on? JSONObject is not available in 6.3...

-What is the exception you are getting?

- Can share sample package with issue

Translate