Как прочитать UID CMSParagraphComponent в представлении - PullRequest
0 голосов
/ 25 марта 2020

Вот то, чего я точно хочу достичь, но у меня не было ответа. Как лучше всего использовать UID CMSParagraphComponent на витрине магазина?

DefaultCMSComponentService

protected Collection<String> getEditorProperties(AbstractCMSComponentModel component, boolean readableOnly) {
    String code = component.getItemtype();
    if (!this.cEditorProperties.containsKey(code)) {
        LOG.debug("caching editor properties for CMSComponent [" + component.getItemtype() + "]");
        List<String> props = new ArrayList();
        Collection<String> systemProps = this.getSystemProperties(component);
        Set<AttributeDescriptorModel> attributeDescriptors = this.getTypeService()
                .getAttributeDescriptorsForType(this.getTypeService().getComposedTypeForCode(code));
        Iterator var8 = attributeDescriptors.iterator();

        while (true) {
            AttributeDescriptorModel ad;
            String qualifier;
            do {
                do {
                    if (!var8.hasNext()) {
                        this.cEditorProperties.put(code, props);
                        return (Collection) this.cEditorProperties.get(code);
                    }

                    ad = (AttributeDescriptorModel) var8.next();
                    qualifier = ad.getQualifier();
                } while (systemProps.contains(qualifier));
            } while (readableOnly && !ad.getReadable());

            props.add(qualifier);
        }
    } else {
        return (Collection) this.cEditorProperties.get(code);
    }
}


public Collection<String> getSystemProperties(AbstractCMSComponentModel component) {
    String code = component.getTypeCode();
    if (!this.cSystemProperties.containsKey(code)) {
        LOG.debug("caching system properties for CMSComponent [" + component.getTypeCode() + "]");
        List props = null;

        try {
            props = (List) Registry.getApplicationContext().getBean(code + "SystemProperties");
        } catch (NoSuchBeanDefinitionException var5) {
            LOG.debug("No bean found for : " + code + "SystemProperties", var5);
            props = this.getSystemProperties();
        }

        this.cSystemProperties.put(code, props);
    }

    return (Collection) this.cSystemProperties.get(code);
}

Не заполняется, поскольку рассматривается как системное свойство. Следовательно, согласно приведенному выше логическому свойству c системное свойство не будет рассматриваться как свойство redable.

Теперь вопрос, как hybris получает список системных свойств для данного типа? Другими словами, где этот компонент Registry.getApplicationContext().getBean(code + "SystemProperties") объявляет?


РЕДАКТИРОВАТЬ: Фактически я знаю, что если для свойства Property атрибута AttributeDescriptor задано значение false, то оно считается системным свойством , Но когда я проверил uid AttributeDescriptor, он (атрибут Property) уже установил значение true.

Ответы [ 2 ]

0 голосов
/ 27 марта 2020

В hybris есть несколько функций, которые используют uid внутри представления. Например, SearchPageController. Чтобы быть более точным c, давайте посмотрим на этот метод:

private static final String COMPONENT_UID_PATH_VARIABLE_PATTERN = "{componentUid:.*}";
...
@ResponseBody
@RequestMapping(value = "/autocomplete/" + COMPONENT_UID_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)
public AutocompleteResultData getAutocompleteSuggestions(...){

final SearchBoxComponentModel component = (SearchBoxComponentModel) cmsComponentService.getSimpleCMSComponent(componentUid);

}

Фактическое значение COMPONENT_UID_PATH_VARIABLE_PATTERN находится в searchboxcomponent.jsp:

<spring:url value="/search/autocomplete/{/componentuid}" var="autocompleteUrl" htmlEscape="false">
      <spring:param name="componentuid"  value="${component.uid}"/>
</spring:url>

Как это Работа? Каждый раз, когда вы что-то вводите, выполняется вызов этой конечной точки с извлечением uid компонента с использованием ${component.uid}.

Почему это работает? Давайте посмотрим на productLayout1Page.jsp и возьмем оттуда простой тег:

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

Теперь мы видим, что есть тег <cms:component component=${..}.../>, который ссылается на экземпляр компонента, и вы можете получить к нему доступ, используя ${component.attributeName} внутри компонента jsp.

0 голосов
/ 26 марта 2020

Кажется, нелегко получить uid на витрине магазина. Но мне удалось сделать это следующим образом:

  • Создать атрибут Dynami c и вернуть значение uid из метода получения
  • Теперь вы можете заполнить этот атрибут Dynami c в интерфейс
...