gpt4 book ai didi

java - 如何覆盖现有属性的@AdminPresentation [Broadleaf Commerce]

转载 作者:行者123 更新时间:2023-11-30 12:05:02 26 4
gpt4 key购买 nike

我正在尝试覆盖 ProductImpl 中定义的以下属性的 @AdminPresentation:

@Column(name = "DISPLAY_TEMPLATE")
@AdminPresentation(friendlyName = "ProductImpl_Product_Display_Template",
group = GroupName.Advanced)
protected String displayTemplate;

目前,由于未提供fieldType 属性,因此默认显示为文本字段。但我想显示一个带有预定义值的下拉选择菜单,例如 ProductPlan。到目前为止,这是我尝试过的:

我创建了一个类 DisplayTemplateType,它实现了 BroadleafEnumerationType 并定义了 PLANPRODUCT 枚举。这是该类的代码:

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 文件中,我添加了以下覆盖属性:

<mo:override id="blMetadataOverrides">
<mo:overrideItem ceilingEntity="org.broadleafcommerce.core.catalog.domain.Product">
<mo:field name="displayTemplate">
<mo:property name="explicitFieldType" value="BROADLEAF_ENUMERATION"/>
<mo:property name="broadleafEnumeration" value="com.community.core.domain.DisplayTemplateType"/>
</mo:field>
</mo:overrideItem>
</mo:override>

但这并没有改变任何东西。我在这里遗漏了什么吗?

最佳答案

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

@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

关于java - 如何覆盖现有属性的@AdminPresentation [Broadleaf Commerce],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56680611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com