我创建了一个动态属性来处理导航节点条目的可见性,与Hybris的所有相关规则兼容。我能够在Java代码中访问该属性而没有遇到任何问题,但是我不能让JSP解释它。***我的DynamicAttributeHandler
类工作顺利,但JSP阅读失败。***以下是创建属性的步骤:
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)注册bean
<bean id="navigationNodeVisibilityAttributeHandler" class="com.inomera.hybris.core.handler.NavigationNodeVisibilityAttributeHandler" />
4)ant clean all && ant updatesystem
每当我在jsp文件中调用它时,我都会得到一个错误,如“..处理JSP页时发生异常..”
<c:forEach items="${component.navigationNode.children}" var="cx">
${cx.navigationNodeVisibility}
</c:forEach>
以这种方式调用属性不会抛出异常,但在我的例子中,有必要在for循环中使用它。${component.navigationNode.children[0].navigationNodeVisibility}
任何帮助或建议将不胜感激
注意:${cx.getNavigationNodeVisibility()}
确实抛出了相同的JSP异常。
编辑:JSP异常示例
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}">
1条答案
按热度按时间0yg35tkg1#
你有没有检查
category
在你的属性处理器中是否不为null?我假设你只允许在你的前端在线目录版本,如果你使用一个类别从分期目录,你会得到一个空值。或者可能有人忘记了在第一时间添加类别。