Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

"Could not find init.jsp" error, and "list" is always null in component

Avatar

Level 4

I have some code in a component where I'm trying to get the list from a request, and it always comes back null. Why is this happening? The other interesting, and probably related, thing, is that when I use a simple " <cq:include script="init.jsp"/>", I get the "Could not find init.jsp" error. When I give an explicit path to init.jsp, (as shown below), it's resolved, but the list always comes back empty. Has anyone seen this??? What's causing this?

 

   // initialize the list
%>

<cq:include script="/libs/wcm/core/components/init/init.jsp"/>

<%
    List list = (List)request.getAttribute("list");
    if (!list.isEmpty()) {

        ...

    }

1 Accepted Solution

Avatar

Correct answer by
Level 10

<cq:include script="init.jsp"/> will only work if the file in which you are calling this is at same location else you need to give relative or full absolute path. As you observed when you give an absolute path, you resolved the issue.

next, coming to List

is this any OOTB component you are working on, are you setting attribute name "list" which you are trying to retrieve ?

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

<cq:include script="init.jsp"/> will only work if the file in which you are calling this is at same location else you need to give relative or full absolute path. As you observed when you give an absolute path, you resolved the issue.

next, coming to List

is this any OOTB component you are working on, are you setting attribute name "list" which you are trying to retrieve ?

Avatar

Level 10

Here is an older community thread that talks about not finding init.jsp:

http://adobe.ly/1RxjVzg

Why a list is empty can be a number of reasons. What is suppose to be in the list. Is this a custom component or an out of the box component?  

Avatar

Level 4

Scott,

It's code that I'd seen in several other OOTB components, and I copied it verbatim. They never explicitly set the attribute, (e.g. request.setAttribute("list", list);), so I didn't either. I thought the code would work same as it did in the other OOTB components. It seemed that it was automatically assigned a value from the dialog based on the Pages/articles the user had chosen/selected when they configured the OOTB component. It allows the developer to get all of the properties they need from the selected page, (e.g. Iimage, title, name, desc, path), so that they can build a link back to the page and display the title etc..

Avatar

Level 4

Thanks. I'd found that other thread, but it didn't really apply. It's interesting that the OOTB components don't explicitly set any attributes, but are able to have that list populated based on what the user selected in the dialog field. Maybe the OOTB components have resources available to them that I don't have set up for my custom component.

Avatar

Level 10

Hi, 

I took a look at OOTB list component, if you see init.jsp, you may notice 

%><%@page import="com.day.cq.wcm.foundation.List, com.day.cq.wcm.api.PageFilter" %><%
%><%@include file="/libs/foundation/global.jsp"%><%
    
List list = new List(slingRequest, new PageFilter());
request.setAttribute("list", list);

 

piece of code present there, which i suppose you might missed.

Avatar

Level 4

 edubey, MANY, Many, many thanks, (and thanks to you too Scott). This one had me spinning my wheels for some time. I know that's to be expected when you're a newb, just learning the technology, but I still can't figure out how the carousel code, (where I'd copied the original snippet), was able to reference the list component's init.jsp, since it's not in the same directory. I just made the unqualified "init.jsp" reference/include, and it worked. I now have all of the meta-data of the page selected by the author so I can display the image, build hrefs/links to the article etc. Thank you so much!