Hybris:如何从上下文中获取枚举的名称?

半径

这是我的代码:

public void onValidate(final Object o, final InterceptorContext ctx) throws InterceptorException
{
    if (o instanceof ProductModel)
    {
        final ProductModel product = (ProductModel) o;
        if (!ctx.isNew(product))
        {

            if (StringUtils.isEmpty(product.getCode()))
            {
                throw new InterceptorException("The Code must not be empty!");
            }
            if (StringUtils.isEmpty(product.getManufacturerName().toString()))
            {
                throw new InterceptorException("The ManufacturerName must not be empty!");
            }               
            if (ctx.isModified(product, ProductModel.MANUFACTURERPRODUCTID)
                    || ctx.isModified(product, ProductModel.MANUFACTURERNAME))
            {

                final boolean b = ProductLookupService.getProductforManufacturerName(product.getManufacturerName().toString());
...    
   }

我需要枚举制造商名称的名称来将其与另一个字符串进行比较,但是我的生成的 getManufacturerName 只返回代码。我有哪些选择?这是 -item.xml 和我生成的 get 方法:

<enumtype code="ManufacturerName" generate="true" autocreate="true" dynamic="true"/>
<itemtype code="Product" generate="false" autocreate="false">
    <attributes>
       <attribute type="ManufacturerName" qualifier="manufacturerName" generate="true">
                    <description> </description>
                    <persistence type="property" />
                </attribute>
...
</attributes>

/**
 * <i>Generated method</i> - Getter of the <code>Product.ManufacturerName</code> attribute defined at extension <code>myextension</code>. 
 * @return the manufacturerName
 */
@Accessor(qualifier = "manufacturerName", type = Accessor.Type.GETTER)
public ManufacturerName getManufacturerName()
{
    return getPersistenceContext().getPropertyValue(MANUFACTURERNAME);
}

再次感谢!

约翰内斯·诺尔特

使用 EnumerationService 的 getEnumerationName() 方法。

import de.hybris.platform.enumeration.EnumerationService;

...

private EnumerationService enumerationService;

...

// Returns current session language name
String name = enumerationService.getEnumerationName(product.getManufacturerName());
// Returns name for a given locale
String englishName = getEnumerationName(product.getManufacturerName(), Locale.ENGLISH);

...

@Required 
public void setEnumerationService(EnumerationService enumerationService) {
    this.enumerationService = enumerationService;
}

春季宣言

<bean id="myClass" ...>
    <property name="enumerationService" ref="enumerationService" />
</bean>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从静态上下文中获取资源内容?

如何从静态上下文中获取getclass()。getResource()?

如何获取Servlet上下文中的所有属性名称(是否嵌套),以及是否是映射或列表进行迭代?

是否可以在GWT UiBinder上下文中引用枚举

Micronaut:从上下文中获取bean的问题

如何从上下文中获取应用程序

如何从反应上下文中获取数据

WPF自动从上下文中列出项目

如何在静态上下文中获取封闭类型的名称?

从上下文中删除不可配置的对象

如何从上下文中获取视图中对象的ID?

无法从上下文中解构对象的属性

使用useEffect在页面加载时从上下文中获取数据

React-如何获取上下文中的钩子值

从上下文菜单获取当前控件名称

如何在TextWatcher方法上下文中获取View?

如果调用方法然后对结果执行.Where(),如何执行“从上下文中的tbl返回(从上下文中的[表名]选择tbl]”)?

SAPUI5如何从上下文中按值获取对象?

从上下文中猜测Num的正确实例

在静态上下文中,当前上下文中不存在某些名称

从上下文获取动作/控制器名称

如何在PHP的继承上下文中从基类中获取属性名称数组?

从上下文中获取活动?

如何从Freemarker宏的上下文中获取Spring bean?

Coq:从上下文中导出参数

如何使用外键从另一个上下文中获取名称?

从上下文菜单更改父按钮名称

如何使用 automapper 在没有主键冲突的情况下添加现有实体而不从上下文中获取它

Flutter HookWidget 从上下文中读取未知