简体   繁体   English

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

[英]Interpreting Dynamic Attribute in JSP in Hybris

I created a dynamic attribute to handle navigation node entries' visibility in compatible with all related rules of Hybris. 我创建了一个动态属性来处理导航节点条目的可见性,以与Hybris的所有相关规则兼容。 I was able to reach the attribute within Java code without getting any problem but I could not make JSP interpret it. 我可以毫无问题地访问Java代码中的属性,但无法让JSP对其进行解释。 My DynamicAttributeHandler class smoothly worked but JSP failed while reading it. 我的DynamicAttributeHandler类运行顺利,但是JSP在读取它时失败。 These were the steps of the creation of the attribute: 这些是创建属性的步骤:

1)items.xml 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 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 3)注册bean

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

4) ant clean all && ant updatesystem 4)蚂蚁清理所有&&蚂蚁更新系统

Whenever I called it in jsp file, I had got an error like ".. An exception occurred processing JSP page .." 每当我在jsp文件中调用它时,都会出现类似“ ..处理JSP页面..时发生异常”的错误。

<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. 以这种方式调用属性不会引发异常,但是在我的情况下,有必要在for循环中使用它。

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

Any help or suggestion would be really appreciated 任何帮助或建议,将不胜感激

Note: ${cx.getNavigationNodeVisibility()} did throw the same JSP exception. 注意: ${cx.getNavigationNodeVisibility()}确实引发了相同的JSP异常。

Edit: JSP exception example 编辑: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}">

Have you checked if the category is not null in your attribute handler? 您是否检查过属性处理程序中的category是否不为null?

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. 我假设您仅在前端允许使用Online目录版本,并且如果您使用暂存目录中的类别,则将获得空值。 Or maybe someone forgot to add the category in the first place. 也许有人忘了先添加类别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM