Emulating requestScope Variables In Sightly For AEM

For one of our clients, that we are doing an AEM implementation for, we have certain pages that we get from a feed and stick in the jcr under each page. The pages have a bunch of components inside.

[name = Some Guy]
[name = ]

We need to prep some of the data by putting it into collections that are easy to spin through and hold them in a bean. But we have to pass that data to components on the page. We don’t want to make the bean a bunch of times.

In JSTL you can easily change the scope of variables:

which is good for passing stuff between JSPS.
Sightly does not have an easy way to do this, so I made one.

Course.java – Use API class that sets up the bean:

package apps.WEBSITE.components.pages.course_page.Course;
public class Course extends WCMUse {
    public void activate() throws Exception {     
        getRequest().setAttribute("courseObject", "a big bean");

course-page.html – top level call to the bean Use API

    whatever components and stuff

author-component.html – some sub component on the page

loop on ${requestUtil.attributes['courseObject'].authors}

RequestUtil.java – util to get attrbutes out of the request

package com.WEBSITE.sightlyutils;
public class RequestUtil extends WCMUse {
    private Map<String, Object> attributes;
    public void activate() throws Exception {
        attributes = new HashMap<String, Object>();
        String attributeName = get("attributeName", String.class);
        attributes.put(attributeName, getRequest().getAttribute(attributeName));
    public Object getAttributes() {
        return attributes;

Here are some additional resources from Stack Overflow if you are interested.