限制 CMS Hybris 中的横幅数量
Restrict Banner numbers in CMS Hybris
我创建了一个 RotatingImagesComponent 并将横幅分配给该组件。
根据要求,需要在 RotatingImagesComponent 中允许最多 6 个横幅。
有人可以告诉我如何实现吗?
在这种情况下我需要创建 CMS 限制吗?
谢谢..
我想你需要一个拦截器
创建实现 PrepareInterceptor
的拦截器
public class RotatingImagesComponentInterceptor implements PrepareInterceptor<RotatingImagesComponentModel> {
....
@Override
public void onPrepare(RotatingImagesComponentModel model, InterceptorContext ctx) throws InterceptorException {
if (CollectionsUtils.isNotEmpty(model.getBanners()) && model.getBanners().size() > 6)
throw new InterceptorException("Only 6 banners are allowed");
}
}
您好,以下是限制横幅数量的步骤。
1 扩展 RotatingImagesComponent 以创建自定义的。
<relation code="SimpleResponsiveBannerComponentToTestRotatingImagesComponent" localized="false">
<deployment table="BannerToTestRotImgRel" typecode="25003"/>
<sourceElement qualifier="rotatingComponent" type="TestRotatingImagesComponent" cardinality="many"/>
<targetElement qualifier="simpleResponsiveBanners" type="SimpleResponsiveBannerComponent" cardinality="many" collectiontype="list" ordered="true"/>
</relation>
<itemtype code="TestRotatingImagesComponent" extends="RotatingImagesComponent" jaloclass="com.company.testcore.jalo.components.TestRotatingImagesComponent">
<description>Image carousel</description>
</itemtype>
2 创建新控制器以根据您的自定义逻辑设置横幅。
package com.company.teststorefront.controllers.cms;
import static java.util.stream.Collectors.toList;
import de.hybris.platform.acceleratorcms.model.components.SimpleResponsiveBannerComponentModel;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.company.testcore.model.components.TestRotatingImagesComponentModel;
import com.company.teststorefront.controllers.ControllerConstants;
/**
* Controller for the TestRotatingImagesComponent{@link TestRotatingImagesComponentModel}
*/
@Controller("TestRotatingImagesComponentController")
@RequestMapping(value = ControllerConstants.Actions.Cms.TestRotatingImagesComponent)
public class TestRotatingImagesComponentController
extends AbstractAcceleratorCMSComponentController<TestRotatingImagesComponentModel> {
private static final String IMAGE_CAROUSEL_BANNERS_ATTRIBUTE = "imageCarouselBanners";
private static final int BANNERS_MAX_SIZE = 5;
@Override
protected void fillModel(HttpServletRequest request, Model model, TestRotatingImagesComponentModel component) {
//@formatter:off
List<SimpleResponsiveBannerComponentModel> limitedBannerList = component.getSimpleResponsiveBanners().stream()
.limit(BANNERS_MAX_SIZE)
.collect(toList());
//@formatter:on
model.addAttribute(IMAGE_CAROUSEL_BANNERS_ATTRIBUTE, limitedBannerList);
}
}
3 创建 testRotatingImagesComponent.jsp 并具有呈现横幅的逻辑。
<%@ page trimDirectiveWhitespaces="true" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="ycommerce" uri="http://hybris.com/tld/ycommercetags" %>
<%@ taglib prefix="image" tagdir="/WEB-INF/tags/responsive/image"%>
<div class="owl-carousel js-owl-carousel js-owl-banner carousel-banner" data-autoplayspeed = "${component.timeout}">
<c:forEach items="${imageCarouselBanners}" var="banner" varStatus="status">
<c:if test="${ycommerce:evaluateRestrictions(banner)}">
<c:url value="${banner.urlLink}" var="encodedUrl" />
<div class="carousel__item">
<a tabindex="-1" href="${encodedUrl}"<c:if test="${banner.urlLink}"> target="_blank"</c:if>>
<image:damImgModel damAsset="${banner.media}" cssClass="carousel-banner__image"/>
</a>
</div>
</c:if>
</c:forEach>
</div>
4 通过添加属性和使用 configurationService 动态控制此变量 BANNERS_MAX_SIZE。
我创建了一个 RotatingImagesComponent 并将横幅分配给该组件。 根据要求,需要在 RotatingImagesComponent 中允许最多 6 个横幅。
有人可以告诉我如何实现吗? 在这种情况下我需要创建 CMS 限制吗?
谢谢..
我想你需要一个拦截器 创建实现 PrepareInterceptor
的拦截器public class RotatingImagesComponentInterceptor implements PrepareInterceptor<RotatingImagesComponentModel> {
....
@Override
public void onPrepare(RotatingImagesComponentModel model, InterceptorContext ctx) throws InterceptorException {
if (CollectionsUtils.isNotEmpty(model.getBanners()) && model.getBanners().size() > 6)
throw new InterceptorException("Only 6 banners are allowed");
}
}
您好,以下是限制横幅数量的步骤。
1 扩展 RotatingImagesComponent 以创建自定义的。
<relation code="SimpleResponsiveBannerComponentToTestRotatingImagesComponent" localized="false">
<deployment table="BannerToTestRotImgRel" typecode="25003"/>
<sourceElement qualifier="rotatingComponent" type="TestRotatingImagesComponent" cardinality="many"/>
<targetElement qualifier="simpleResponsiveBanners" type="SimpleResponsiveBannerComponent" cardinality="many" collectiontype="list" ordered="true"/>
</relation>
<itemtype code="TestRotatingImagesComponent" extends="RotatingImagesComponent" jaloclass="com.company.testcore.jalo.components.TestRotatingImagesComponent">
<description>Image carousel</description>
</itemtype>
2 创建新控制器以根据您的自定义逻辑设置横幅。
package com.company.teststorefront.controllers.cms;
import static java.util.stream.Collectors.toList;
import de.hybris.platform.acceleratorcms.model.components.SimpleResponsiveBannerComponentModel;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.company.testcore.model.components.TestRotatingImagesComponentModel;
import com.company.teststorefront.controllers.ControllerConstants;
/**
* Controller for the TestRotatingImagesComponent{@link TestRotatingImagesComponentModel}
*/
@Controller("TestRotatingImagesComponentController")
@RequestMapping(value = ControllerConstants.Actions.Cms.TestRotatingImagesComponent)
public class TestRotatingImagesComponentController
extends AbstractAcceleratorCMSComponentController<TestRotatingImagesComponentModel> {
private static final String IMAGE_CAROUSEL_BANNERS_ATTRIBUTE = "imageCarouselBanners";
private static final int BANNERS_MAX_SIZE = 5;
@Override
protected void fillModel(HttpServletRequest request, Model model, TestRotatingImagesComponentModel component) {
//@formatter:off
List<SimpleResponsiveBannerComponentModel> limitedBannerList = component.getSimpleResponsiveBanners().stream()
.limit(BANNERS_MAX_SIZE)
.collect(toList());
//@formatter:on
model.addAttribute(IMAGE_CAROUSEL_BANNERS_ATTRIBUTE, limitedBannerList);
}
}
3 创建 testRotatingImagesComponent.jsp 并具有呈现横幅的逻辑。
<%@ page trimDirectiveWhitespaces="true" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="ycommerce" uri="http://hybris.com/tld/ycommercetags" %>
<%@ taglib prefix="image" tagdir="/WEB-INF/tags/responsive/image"%>
<div class="owl-carousel js-owl-carousel js-owl-banner carousel-banner" data-autoplayspeed = "${component.timeout}">
<c:forEach items="${imageCarouselBanners}" var="banner" varStatus="status">
<c:if test="${ycommerce:evaluateRestrictions(banner)}">
<c:url value="${banner.urlLink}" var="encodedUrl" />
<div class="carousel__item">
<a tabindex="-1" href="${encodedUrl}"<c:if test="${banner.urlLink}"> target="_blank"</c:if>>
<image:damImgModel damAsset="${banner.media}" cssClass="carousel-banner__image"/>
</a>
</div>
</c:if>
</c:forEach>
</div>
4 通过添加属性和使用 configurationService 动态控制此变量 BANNERS_MAX_SIZE。