如何为现有属性覆盖@AdminPresentation [Broadleaf Commerce]

时间:2019-06-20 06:59:06

标签: java spring spring-mvc broadleaf-commerce

我正在尝试覆盖bool outlierScore::operator<(const outlierScore& other) const { return std::tie(score, coreDistance, id) < std::tie(other.score, other.coreDistance, other.id); } 中定义的以下属性的@AdminPresentation

ProductImpl

由于没有提供@Column(name = "DISPLAY_TEMPLATE") @AdminPresentation(friendlyName = "ProductImpl_Product_Display_Template", group = GroupName.Advanced) protected String displayTemplate; 属性,当前默认情况下将其显示为文本字段。但是我想显示一个具有预定义值的下拉选择菜单,例如fieldTypeProduct。到目前为止,这是我尝试过的:

我创建了一个实现Plan并定义了DisplayTemplateTypeBroadleafEnumerationType枚举的类PLAN。这是该类的代码:

PRODUCT

然后在public class DisplayTemplateType implements Serializable, BroadleafEnumerationType { private static final long serialVersionUID = 7761108654549553693L; private static final Map<String, DisplayTemplateType> TYPES = new LinkedHashMap<String, DisplayTemplateType>(); public static final DisplayTemplateType PLAN = new DisplayTemplateType("PLAN", "PLAN"); public static final DisplayTemplateType PRODUCT = new DisplayTemplateType("PRODUCT", "PRODUCT"); public static DisplayTemplateType getInstance(final String type) { return TYPES.get(type); } private String type; private String friendlyType; public DisplayTemplateType() { //do nothing } public DisplayTemplateType(final String type, final String friendlyType) { this.friendlyType = friendlyType; setType(type); } @Override public String getType() { return type; } @Override public String getFriendlyType() { return friendlyType; } private void setType(final String type) { this.type = type; if (!TYPES.containsKey(type)) { TYPES.put(type, this); } else { throw new RuntimeException("Cannot add the type: (" + type + "). It already exists as a type via " + getInstance(type).getClass().getName()); } } // equals() and hashCode() implementation is removed for readability } 文件中,我添加了以下覆盖属性:

applicationContext-admin.xml

但是它并没有改变任何东西。我在这里想念东西吗?

1 个答案:

答案 0 :(得分:0)

最后,在尝试了许多事情之后,我想出了一种解决方法。与使用基于XML的方法不同,我不得不扩展ProductImpl类以覆盖其属性@AdminPresentation。但是对于扩展,我需要定义一个@Entity,因此,我需要创建一个无用的表来绑定到该实体。我知道这不是完美的方法,但是我找不到任何更好的解决方案。这是我的代码,以便将来有人可以从中获得帮助:

@Entity
@Immutable
@AdminPresentationMergeOverrides({
        @AdminPresentationMergeOverride(name = "displayTemplate", mergeEntries = {
                @AdminPresentationMergeEntry(propertyType = PropertyType.AdminPresentation.FIELDTYPE, overrideValue = "BROADLEAF_ENUMERATION"),
                @AdminPresentationMergeEntry(propertyType = PropertyType.AdminPresentation.BROADLEAFENUMERATION, overrideValue = "com.community.core.domain.DisplayTemplateType"),
                @AdminPresentationMergeEntry(propertyType = PropertyType.AdminPresentation.REQUIREDOVERRIDE, overrideValue = "REQUIRED"),
                @AdminPresentationMergeEntry(propertyType = PropertyType.AdminPresentation.DEFAULTVALUE, overrideValue = "PLAN")
        })
})
public class CustomProduct extends ProductImpl {

    private static final long serialVersionUID = -5745207984235258075L;
}

现在是这样显示的:

This is how it is displayed now