简体   繁体   English

Hybris:如何将我的jsp标记添加到位于另一个扩展中的另一个jsp标记内

[英]Hybris: how to add my jsp tag inside another jsp tag which locates in another extention

I created addon and jsp tag, which is located at : bin\\custom\\Myaddon\\acceleratoraddon\\web\\webroot\\WEB-INF\\tags\\desctop\\product\\productList.tag 我创建了addon和jsp标记,它们位于:bin \\ custom \\ Myaddon \\ acceleratoraddon \\ web \\ webroot \\ WEB-INF \\ tags \\ desctop \\ product \\ productList.tag

Here is code of productList.tag: 这是productList.tag的代码:

 <%@ tag body-content="empty" trimDirectiveWhitespaces="true" %>
 <%@ attribute name="product" required="true" type="de.hybris.platform.commercefacades.product.data.ProductData" %>

 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
 <%@ taglib prefix="ycommerce" uri="http://hybris.com/tld/ycommercetags" %>


 <div class="addmybutton">
       <form id="add_to_list_form" action="${addToListUrl}" method="post">
        <input name="code" type="hidden" value="${product.code}"/>
        <input name="isPostponed" type="hidden" value="false"/>
        <input type="hidden" name="CSRFToken" value="${CSRFToken.token}">
        <button id="add_to_list_submit_button" type="submit" class="b-btn b-btn--red i-fs14"><spring:theme
                code="text.addToMyList"/></button>
    </form>
  </div>

How i can make this jsp tag appear inside the jsp page (or any jsp tag) which locates in storefront? 我如何使这个jsp标签出现在位于店面的jsp页面(或任何jsp标签)内?

For instance, if I want to add my jsp tag to productLayout1Page.jsp (which automatically created when we create storefront extention). 例如,如果我要将jsp标记添加到productLayout1Page.jsp(在创建店面扩展时会自动创建)。

Location of productLayout1Page.jsp: bin\\custom\\myModule\\myModulestorefront\\web\\webroot\\WEB-INF\\views\\responsive\\pages\\product\\productLayout1Page.jsp productLayout1Page.jsp的位置:bin \\ custom \\ myModule \\ myModulestorefront \\ web \\ webroot \\ WEB-INF \\ views \\ responding \\ pages \\ product \\ productLayout1Page.jsp

Here is a code of productLayout1Page.jsp: 这是productLayout1Page.jsp的代码:

 <%@ page trimDirectiveWhitespaces="true"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <%@ taglib prefix="template" tagdir="/WEB-INF/tags/responsive/template"%>
 <%@ taglib prefix="cms" uri="http://hybris.com/tld/cmstags"%>
 <%@ taglib prefix="product" tagdir="/WEB-INF/tags/responsive/product"%>

</cms:pageSlot>
<product:productDetailsPanel />
<cms:pageSlot position="CrossSelling" var="comp" element="div" class="productDetailsPageSectionCrossSelling">
    <cms:component component="${comp}" element="div" class="productDetailsPageSectionCrossSelling-component"/>
</cms:pageSlot>

<cms:pageSlot position="Section2" var="comp" element="div" class="productDetailsPageSection2">
    <cms:component component="${comp}" element="div" class="productDetailsPageSection2-component"/>
</cms:pageSlot>

<cms:pageSlot position="Section3" var="comp" element="div" class="productDetailsPageSection3">
    <cms:component component="${comp}" element="div" class="productDetailsPageSection3-component"/>
</cms:pageSlot>
<cms:pageSlot position="UpSelling" var="comp" element="div" class="productDetailsPageSectionUpSelling">
    <cms:component component="${comp}" element="div" class="productDetailsPageSectionUpSelling-component"/>
</cms:pageSlot>
<product:productPageTabs />
<cms:pageSlot position="Section4" var="comp" element="div" class="productDetailsPageSection4">
    <cms:component component="${comp}" element="div" class="productDetailsPageSection4-component"/>
</cms:pageSlot>

I should add code only to my addon. 我应该只将代码添加到我的插件中。 All changes should appear on storefront only after ant all . 所有更改应仅在ant all之后出现在店面中。

Elena 埃琳娜(Elena)

  1. First you need to place your tags under any sub folder in WEB-INF\\tags. 首先,您需要将标签放置在WEB-INF \\ tags中的任何子文件夹下。 I see you already place there. 我看到你已经放在那里了。

  2. Second you need to import your tags in any other jsp or tags like below. 其次,您需要将标签导入任何其他jsp或标签,如下所示。

    <%@ taglib prefix="myOwnTag" tagdir="/WEB-INF/tags/custom/folder/" %>

    In the tagdir, Do not mention the tag name, just leave until the directory it is in. So in your case this will be <%@ taglib prefix="myOwnTag" tagdir="WEB-INF\\tags\\desctop\\product" %> 在tagdir中,不要提及标签名称,只保留它所在的目录即可。因此,在您的情况下,这将是<%@ taglib prefix="myOwnTag" tagdir="WEB-INF\\tags\\desctop\\product" %>

  3. use the tag like below whether in jsp or another tag 在jsp或其他标签中使用如下标签

    <prefix-mentioned-above:name-of-the-tag/>

    In your case this will be 在您的情况下,这将是

    <myOwnTag:productList/>

Check my code in the image. 检查图像中的代码。 I created an year.tag which i used in an other.tag which i used in index.jsp page. 我创建了一个year.tagother.tag其用于index.jsp页面中的other.tag

在这里检查我的代码

Hope this helps you how to use tags in jsp's and another tag's. 希望这可以帮助您如何在jsp和另一个标签中使用标签。

If you want to edit html content of a page without making changes to the storefronts files, you have 2 options: 如果要编辑页面的html内容而不更改店面文件,则有两个选项:

  1. Use existing content slots and adding cms components/actions to them. 使用现有的内容插槽,并向其添加cms组件/操作。 You can create components/actions inside your addon and add those components to your content slot using impex/cms cockpit. 您可以在插件内部创建组件/动作,然后使用impex / cms座舱将这些组件添加到内容插槽中。 This option is very limited since you are constrained to existing content slots. 由于您只能使用现有的内容位置,因此此选项非常有限。 more 更多
  2. Create a completely new page inside an addon and overwrite the page in your storefront. 在插件中创建一个全新的页面,并覆盖店面中的页面。 This option involes a lot of copying content from A to B and i would not recommend it. 此选项涉及从A到B的大量复制内容,我不建议这样做。 If there is no really really good reason to use this option, consider option 1 or change the files in the storefont. 如果没有真的很好的理由使用此选项,请考虑选项1或更改storefont中的文件。 more 更多

In a lot of cases it is almost inevitable to change the content of the jsp files in the storefront. 在许多情况下,几乎不可避免的是要在店面中更改jsp文件的内容。

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

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