Expand my Community achievements bar.

Unable to render url or html content as page via sightly

Avatar

Level 2

Currently in our project, the 404 error page are customized for diff locale and brands.

The redirect is happening via IIS, where all our URL redirect logic is handled like url shortening etc. No issue here.

 

Problem statement : Current 404 page redirect logic is handled via model class extending WCMUsePojo where we query aem for 404 page and return the appropriate 404 page content which is html by calling this page as resource and fetching the html content and returning this through a getter method via model class. This rendering of html page content initially was done via jsp page but the problem is coming when it is converted to sightly. With jsp page logic it works fine.

The sample jsp content is : 

<%@page session="false" contentType="text/html; charset=utf-8" %><%

%><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%

%><%@include file="/apps/corporate/global.jsp" %><%

%><cq:defineObjects/><%

 

%><jsp:useBean id="componentBean" scope="page" class="corporate.core.components.page.globalerrorpage.GlobalErrorpageComponentBean" /><%

%><jsp:setProperty name="componentBean" property="slingResponse" value="<%=slingResponse%>" /><%

%><jsp:setProperty name="componentBean" property="slingRequest" value="<%=slingRequest%>" /><%

 

%><c:if test="${not componentBean.disabledMode}">global errorpage. no content will be shown in author mode</c:if><%

%><c:if test="${componentBean.disabledMode}">${componentBean.errorpageContent}</c:if>

 

and  

Its sightly equivalent is :

<div data-sly-use.componentBean="corporate.core.components.page.GlobalErrorpageComponentBean" data-sly-unwrap>

<sly data-sly-test="${!componentBean.publish}">global errorpage. no content will be shown in author mode

</sly>

<sly data-sly-test="${componentBean.publish}">${componentBean.errorpageContent}

</sly>

</div>

 

 

Model class GlobalErrorpageComponentBean:

 

getErrorpageContent(final String errorpagePath) throws ServletException, IOException {

final SlingRequestProcessor requestProcessor = this.getService(SlingRequestProcessor.class);

final RequestResponseFactory requestResponseFactory = this.getService(RequestResponseFactory.class);

 

final HttpServletRequest request = requestResponseFactory.createRequest("GET", errorpagePath + ".html");

 

final ByteArrayOutputStream outByte = new ByteArrayOutputStream();

final HttpServletResponse response = requestResponseFactory.createResponse(outByte);

 

requestProcessor.processRequest(request, response, this.getResourceResolver());

 

final String pageContent = new String(outByte.toByteArray(), CharEncoding.UTF_8);

 

return pageContent;

}

 

 

The errorpagePath is found by query which gives appropriate result like "/content/project_global/en_CN/404".

 

During rendering via sightly, we get the html page content in network tab preview section, but it is not rendering on the page.  the page has white screen. The request status in network tab is 404, but the body doesn't load at all. Even the page title is not 404 which is property "htmlTitle" of the 404 error page.

 

 

Can anyone help here? 

 

7 Replies

Avatar

Level 8

@MaheshKPati  suggest to avoid render HTML dom content via slightly / pojo, rather create a standard HTML 5 as per your requirement and pass slightly/Pojo data to corresponding dom element

Avatar

Level 2

I have tried this html change in our GlobalErrorPage body.html, to which IIS redirect user to in 404 cases.

 

In body.html ,

<div data-sly-use.componentBean="io.ecx.axalta.aem.axbase.core.components.page.GlobalErrorpageComponentBean" data-sly-unwrap>
<sly data-sly-test="${!componentBean.isPublish}">global errorpage. no content will be shown in author mode
</sly>       
        <sly data-sly-test="${componentBean.isPublish}">
        <sly data-sly-resource="${@path=componentBean.errorPagePath}.html"></sly>
        </sly>
</div>
 
where, componentBean.errorPagePath = /content/project_global/en_CN/404 or any similar 404 page as return by our search query within aem based on project.
 
Even if I do not render HTML dom content via slightly, i am trying to redirect to /content/project_global/en_CN/404 page but it is not rendering the entire 404 page. Only the body is rendered but not the header and footer of 404 page. Via jsp page, as stated in my initial comment, if i try to render the html source of 404 page, it is rendering the entire 404 page content and url remains the one which is enter by user, for which corresponding page is not present in AEM. I do not know what is the difference here.
 
NOTE: Now since this is error page handler , i can not redirect user explicitly to 404 page. User should remain at any wrong page url which has been entered, only the content of the page should be the 404 page as the requested page doesn't exist.

Avatar

Community Advisor

Hi @MaheshKPati 
I would go for dispatcher to configure all the error pages, (including language/multisite), please check

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-dispatcher-errordocume... 



Arun Patidar

Avatar

Community Advisor

If you are saying that you are seeing the expected html in network tab as well as correct response code and it is just not rendering on the browser, I think it might be some missing config on IIS side.
Could you try checking the response headers once, especially the Content-Type header ? 


Avatar

Administrator

@MaheshKPati Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni

Avatar

Level 2

I am exploring the areas as suggested, will revert back once found appropriate solution.