在 Hybris 中解释 JSP 中的动态属性

Interpreting Dynamic Attribute in JSP in Hybris

我创建了一个动态属性来处理与 Hybris 所有相关规则兼容的导航节点条目的可见性。我能够在 Java 代码中访问属性而没有遇到任何问题,但我无法让 JSP 解释它。 我的 DynamicAttributeHandler class 运行顺利,但 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}">

您是否检查过属性处理程序中的 category 是否不为空?

我假设您只允许在前端使用在线目录版本,如果您使用暂存目录中的类别,您将得到一个空值。或者也许有人忘记首先添加类别。