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}">
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.