【问题标题】:Hybris component in Addon not calling controllerAddon 中的 Hybris 组件不调用控制器
【发布时间】:2019-02-24 15:08:32
【问题描述】:

我创建了我的自定义表单组件。我在智能编辑中添加后,它不会调用控制器来填写表单。 我在 *-items.xml 中创建了 itemtype MyComponentModel,检查了 HAC 部署,它就在那里。 我还添加了类似 answer

的注释
@Controller("MyComponentController")
@RequestMapping(value = ControllerConstants.Actions.Cms.MyComponent)
public class MyComponentController extends AbstractAcceleratorCMSComponentController<MyComponentModel> {

映射值在我的 ControllerConstants 中,如下所示:

String _Prefix = "/view/"; // NOSONAR
String _Suffix = "Controller"; // NOSONAR
String MyComponent = _Prefix + MyComponentModel._TYPECODE + _Suffix; // NOSONAR

当我在页面上的 smartedit 中添加它时,会加载 .jsp 文件(我可以看到一些文本),但由于没有调用控制器

根据 Hybris 文档,我的控制器中被调用的方法应该是这样的:

@Override
protected void fillModel(HttpServletRequest request, Model model, MyComponentModel component) {

但它没有被调用,所以我无法填写表格。

<div class="span-20 last">
    I can see this text
    <div class="row item_container_holder">
        <c:if test="${not empty MyForm}">
          <%--this condition is false, form is empty--%>

请注意,我还在 impex 中添加了组件,我在 HAC 中更新了系统,我尝试同步目录。

INSERT_UPDATE MyComponent; $contentCV[unique = true]; uid[unique = true]       ; name                               ; &componentRef
;; MyComponent ; MyComponent ; MyComponent

编辑:

*-items.xml

 <itemtype code="MyComponent" autocreate="true" generate="true" extends="SimpleCMSComponent"
              jaloclass="mypackage.b2c.core.jalo.components.MyComponent">
        <deployment table="MyComponents" typecode="15900"/>
        <attributes>
            <attribute qualifier="title" type="localized:java.lang.String">
                <persistence type="property" />
                <modifiers />
                <description>Localized title of the component.</description>
            </attribute>
        </attributes>
    </itemtype>

【问题讨论】:

  • 为 MyComponentModel 添加您的 *items.xml。首先,您的 Impex 在这里似乎错了
  • 你想在你的插件中创建这个组件吗?如果是,请关注this answer
  • 我编辑了一个 impex。是的,这是我的插件。现在它正在调用控制器,但它找不到 .jsp 文件。我把它放在路径/WEB-INF/views/responsive/cms,但我仍然收到错误Error processing component tag. currentComponent [MyComponentModel (8796093136412@1)] exception: File [/WEB-INF/views/responsive/cms/myComponent.jsp] not found
  • 检查我的答案

标签: java hybris


【解决方案1】:

正如您所说,您正在尝试在插件中创建此组件

确保您按照我提到的步骤here

您的评论:我把它放在路径 /WEB-INF/views/responsive/cms 上,但我仍然得到一个 error 处理组件标签时出错。当前组件 [MyComponentModel (8796093136412@1)] 异常:File [/WEB-INF/views/responsive/cms/myComponent.jsp] not found

调试AbstractCMSAddOnComponentControllergetView方法来检查路径。

您必须将您的 jsp 添加到 /youraddon/acceleratoraddon/web/webroot/WEB-INF/views/responsive/cms/myComponent.jsp,稍后将在构建过程中将其复制到您的 stroefront 扩展中。

【讨论】:

    【解决方案2】:

    为 cms 组件调用的控制器取决于 itemtype。您不能创建 JspIncludeComponent 并期望调用 MyComponent 的组件控制器。

    试试这个:

    INSERT_UPDATE MyComponent;...
    

    【讨论】:

    • 我尝试了这个解决方案,但是如何定义我的 .jsp 文件的路径?我已经把它放到路径/WEB-INF/views/responsive/cms,但它仍然给我一个错误Error processing component tag. currentComponent [MyComponentModel (8796093136412@1)] exception: File [/WEB-INF/views/responsive/cms/myComponent.jsp] not found,但我可以在那里看到那个文件。
    • 考虑这个类:de.hybris.training.storefront.controllers.cms.AbstractAcceleratorCMSComponentController getView 方法描述了如何为 cms 组件解析视图。
    • 在你的情况下应该是 WEB-INF/views/desktop/cms/mycomponent.jsp。根据设置的体验级别,您必须使用响应式或移动文件夹而不是桌面。
    • 一般情况下它们应该在“WEB-INF/views/desktop/cms/”+你的组件的小写名称+jsp。
    • 对于插件中的组件,它有点棘手。您的 Controller 需要扩展 de.hybris.platform.addonsupport.controllers.cms.GenericCMSAddOnComponentController。 de.hybris.platform.addonsupport.controllers.cms.AbstractCMSAddOnComponentController 中的超类方法 getView 然后确定视图。将你的 jsp 文件放在 myaddon/web/webroot/WEB-INF/views/desktop/cms/ 中,使用相同的小写名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    • 2017-02-01
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多