HYBRIS-JSP文件中的组件和插槽如何工作? [英] HYBRIS - How components and slots work in JSP file?

查看:119
本文介绍了HYBRIS-JSP文件中的组件和插槽如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我正在使用Hybris,但我不了解组件的工作原理.

Recently I am working with Hybris, and I can not understand how the components work.

我知道如何创建和定义一个,如何将它们添加到我想要的页面中,等等.但是我不明白如何在jsp文件中使用标记<cms: component>.

I know how to create and define one, how to add them to the page I want, etc. But I do not understand how to use the tag <cms: component> in the jsp file.

在产品详细信息页面的插槽AddToCartSlot中,我添加了更多组件.我试图像标准一样调用组件,并注释其行.

In the slot AddToCartSlot from the product detail page, I added more components. I tried to call my component as does the standard and comment his lines.

默认情况下,它称为组件:

By default, it is called the component as follows:

<cms:pageSlot position="AddToCart" var="component">
   <cms:component component="${component}" />
</cms:pageSlot>

所以我也尝试调用我的组件,但是不起作用:

So I tried to call my component as well, but does not work:

<cms:pageSlot position="MyComponent" var="component">
   <cms:component component="${component}" />
</cms:pageSlot>

因此,我的台词对他的台词进行了注释和取消注释,所有组件均显示在页面上. 但是对我而言,这没有任何意义,因为在标签cms:pageSlot的position属性中应该接收插槽的ID,而不是用来显示所有插槽的组件的ID.但是,将id AddToCart代替AddToCartSlot是在页面上显示所有组件的唯一方法.

So my lines commented and uncommented his lines, and all components are shown on the page. But for me this makes no sense because in the position attribute of the tag cms:pageSlot should received the id of a slot and not the id of a component to show all components slot. However, putting the id AddToCartinstead of AddToCartSlot is the only way that all components are displayed on the page.

现在,您将考虑如果这些组件在Web上显示会出现什么问题?",那么问题是这些组件没有经过与它们相对应的Java控制器(尽管已在该组件中创建并声明了这些组件) com.myStore.storefront.controllers.ControllerConstants.java文件).此外,我想了解为什么它无法正常工作.

Now you will think 'what the problem if the components are being displayed on the web?', well, the problem is that these components are not going through the java controller that corresponds to them (despite being created and declared in the com.myStore.storefront.controllers.ControllerConstants.java file). In addition, I would like to understand why it is not working properly.

我遵循了Wki Hybris的步骤,发现所有内容都被声明为可以正常工作的另一个自定义组件.我找不到差异,也无法理解为什么不通过我的控制器,或者为什么标记与插槽的ID一起无法正常工作,但是当我使用组件的标识符时,标记起作用".

I followed the steps of Wki Hybris and I found that everything is declared as it is to another custom component that's working properly. I can not find differences and I can not understand why not pass my controller or why the tag does not work as it should with the id of the slot, but it "works" when I use the identifier of a component.

真的,任何想法都会有所帮助.

Really, any ideas will help.

非常感谢您.

推荐答案

为使Hybris使用控制器,控制器应该是这样的:

This is how the controller should look like in order for Hybris to use it:

@Controller("CustomCMSImageComponentController")
@RequestMapping(value = ControllerConstants.CustomCMSImageComponent )// now the controller is mapped to "/view/CustomCMSImageComponentController"
public class CustomCMSImageComponentController extends AbstractCMSComponentController<CustomCMSImageComponentModel> {
    @Override
    protected void fillModel(final HttpServletRequest request, final Model model,
                       final CustomCMSImageComponentModelcomponent) {
    //here the spring Model(model method parameter) should be filled with what is needed to dynamically render in JSP
    }
}

Spring使用@Controller注释实例化CustomCMSImageComponentController并将该实例(bean)保留在 春天的应用程序上下文.

The @Controller annotation is used by Spring to instantiate the CustomCMSImageComponentController and keep that instance(bean) in the spring application context.

在渲染CustomCMSImageComponent时,Hybris在spring应用程序上下文中搜索名称为"CustomCMSImageComponentController"的bean,以便 找到与组件关联的Controller,如果找不到任何内容,将使用DefaultCMSComponentController.

When rendering the CustomCMSImageComponent Hybris searches after the bean with the name "CustomCMSImageComponentController" in the spring application context in order to find the Controller associated with the component and if it does not find anything the DefaultCMSComponentController will be used.

这篇关于HYBRIS-JSP文件中的组件和插槽如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆