InsideAEM Limited: Expert knowledge for Adobe Experience Manager and Adobe Marketing Cloud Expert knowledge for Adobe Experience Manager and Adobe Marketing Cloud

Have a Question?

Start typing below to have an answer about Adobe Experience Manager!

How to use $PATH in a Widget to populate an options Data

1) Example  with Servlet

@Component(immediate = true, metatype = false)
 @Service(value = Servlet.class)
 @Properties(value = {
 @Property(name = "sling.servlet.methods", value = "GET"),
 @Property(name = "sling.servlet.resourceTypes", value = Your RESOURCE_TYPE),
 @Property(name = "sling.servlet.extensions", value = "<strong>myoptions</strong>")
 })

public class TestOptionsServlet extends SlingSafeMethodsServlet {

@Override
 public final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
 throws ServletException, IOException {
 response.setContentType("application/json");
 response.setCharacterEncoding("UTF-8");
 final Resource resource = request.getResource(); // detail page
 Node node = resource.adaptTo(Node.class);
 writeResponse(response.getWriter(), node);
 }

private void writeResponse(final Writer writer, final Node node) throws IOException {

try {
 final TidyJSONWriter w = new TidyJSONWriter(writer);
 w.setTidy(false);
 w.array();
 NodeIterator nodes = node.getNodes();
 while (nodes.hasNext()) {
 w.object();
 Node nextNode = (Node)nodes.next();
 w.key("value").value("node Name");
 w.key("text").value(nextNode.getName());
 w.endObject();
 }
 w.endArray();
 } catch (final Exception e) {

}
 }
 }

2) now go to your Widget for example dialog.xml and add this configuration

<jcr:primaryType="cq:Widget"
 fieldLabel="Test Options"
 name="./myData"
 xtype="selection"
 type="checkbox"
 options="$PATH.myoptions"/>

Note:  you can use  jsp instead of Servlet to create options data

Leave a Reply

You must be logged in to post a comment.