4

I created a dynamic attribute to handle navigation node entries' visibility in compatible with all related rules of Hybris. I was able to reach the attribute within Java code without getting any problem but I could not make JSP interpret it. My DynamicAttributeHandler class smoothly worked but JSP failed while reading it. These were the steps of the creation of the attribute:

1)items.xml

<attribute qualifier="navigationNodeVisibility" type="java.lang.Boolean">
       <persistence type="dynamic" attributeHandler="navigationNodeVisibilityAttributeHandler"/>
       <modifiers read="true" write="false" search="true"/>
       <defaultvalue>java.lang.Boolean.TRUE</defaultvalue>
</attribute>

2)NavigationNodeVisibilityAttributeHandler.java

@Override
public Boolean get(CMSNavigationNodeModel model) {
    if (model != null) {
        for(CMSNavigationEntryModel cmsNavigationEntry:model.getEntries()){
            if(cmsNavigationEntry.getItem() instanceof  CMSLinkComponentModel){
                CategoryModel category= ((CMSLinkComponentModel)cmsNavigationEntry.getItem()).getCategory();
                if((category.getVisibility()== null || category.getVisibility() ) && ActiveProductStatus.ACTIVE == category.getActiveProductStatus()
                        && ManageCategoryByDateStatus.ACTIVE == category.getManageCategoryByDateStatus()){
                    return Boolean.TRUE;
                }
            }
        }
        return Boolean.FALSE;
    }
    return null;
}

3) Registering bean

<bean id="navigationNodeVisibilityAttributeHandler" class="com.inomera.hybris.core.handler.NavigationNodeVisibilityAttributeHandler" />

4) ant clean all && ant updatesystem

Whenever I called it in jsp file, I had got an error like ".. An exception occurred processing JSP page .."

<c:forEach items="${component.navigationNode.children}" var="cx">
    ${cx.navigationNodeVisibility}
</c:forEach>

Calling the attribute in this way did not throw an exception but it is necessary to use it within the for loop in my case.

${component.navigationNode.children[0].navigationNodeVisibility}

Any help or suggestion would be really appreciated

Note: ${cx.getNavigationNodeVisibility()} did throw the same JSP exception.

Edit: JSP exception example

WARN  [hybrisHTTP14] [XXXXXXXXXXXX] [DefaultCMSComponentRendererRegistry] Error processing component tag. currentComponent [CategoryNavigationComponentModel (8796098036796@1)] exception: An exception occurred processing JSP page /WEB-INF/views/responsive/cms/categorynavigationcomponent.jsp at line 14

11: <nav id="menu" style="display: none;">
12:         <ul>
13:             <c:forEach items="${component.navigationNode.children}" var="childLevel1">
14:                 <c:if test="${ childLevel1.visible eq 'true' && childLevel1.navigationNodeVisibility}">
15:                     <li>
16:                         <c:forEach items="${childLevel1.entries}" var="childEntry1" end="1">
17:                             <c:if test="${not empty childLevel1.children}">
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Hatip Kabak
  • 316
  • 2
  • 22
  • How does the JSP exception Look like ? – dj_frunza Sep 09 '18 at 05:40
  • 1
    Have you checked if the `category` is not null in your attribute handler? I'm assuming you only allow the Online catalog version in your frontend, and if you use a category from the Staged catalog, you will get a null value. – Sukram Sep 10 '18 at 07:19
  • 1
    I realized that some categories related to navigation nodes was null yesterday night. I would write here if i had the opportunity during the day. You are fast with me. Yeah, it was totally because some categories are null. – Hatip Kabak Sep 10 '18 at 08:10
  • @hatipkabak If you would be so kind to accept my answer... – Sukram Sep 11 '18 at 09:51

1 Answers1

2

Have you checked if the category is not null in your attribute handler?

I'm assuming you only allow the Online catalog version in your frontend, and if you use a category from the Staged catalog, you will get a null value. Or maybe someone forgot to add the category in the first place.

Sukram
  • 381
  • 2
  • 6