猿问

Hybris 自定义电子邮件设置自定义属性

我正在创建一个自定义电子邮件,应在填写预约表格后发送给客户。我需要额外的属性,所以我扩展了AbstractEmailContext:


public class AppointmentEmailContext extends AbstractEmailContext

{

   private String myAttribute;

   ...

}

在我开始这个过程之前,我正在我的 EventListener 中设置属性:


final AppointmentProcessModel storeFrontCustomerProcessModel = (AppointmentProcessModel) getBusinessProcessService()

                .createProcess(

                        "appointmentEmailProcess-" + event.getEmail() + "-" + System.currentTimeMillis(),

                        "appointmentEmailProcess");


storeFrontCustomerProcessModel.setMyAttribute("test@test.com");

getModelService().save(storeFrontCustomerProcessModel);

getBusinessProcessService().startProcess(storeFrontCustomerProcessModel);

在我无法获取这些参数的init方法中,AppointmentEmailContext我可以正确设置它们并将它们传递给电子邮件模板。另一件事是,在init方法中输入的 ProcessModel不是 的实例AppointmentProcessModel,而是 的实例StoreFrontCustomerProcessModel,即使我AppointmentProcessModel正在扩展它。


我也尝试添加AppointmentProcessModel这样的:


public class AppointmentEmailContext extends AbstractEmailContext<AppointmentProcessModel>

{

...

}

并使用正确的参数调整 init 方法(+ 添加覆盖方法),但随后在创建过程时出现错误:


ERROR [hybrisHTTP21] [HybrisApplicationEventMulticaster] java.lang.InstantiationException: mypackage.core.appointment.model.AppointmentProcessModel

 java.lang.RuntimeException: java.lang.InstantiationException: mypackage.core.appointment.model.AppointmentProcessModel

我不知道保留这些属性是否有问题,或者我是否应该以其他方式传递这些属性。


更新:我试图添加AppointmentProcess到*-items.xml文件,我做系统更新,但没有改变。我在后台检查了该类型已添加并且它是从StoreFrontCustomerProcess. 定义如下:


        <itemtype code="AppointmentProcess" extends="StoreFrontCustomerProcess"

                  autocreate="true" generate="true"

                  jaloclass="mypackage.jalo.AppointmentProcess">

            <attributes>

                <attribute qualifier="email" type="java.lang.String">

                    <persistence type="property" />

                </attribute>

            </attributes>

        </itemtype>


慕的地10843
浏览 152回答 1
1回答

海绵宝宝撒

通过 HMC 交叉验证,您的属性是否保存在 storeFrontCustomerProcessModel 中?尝试更改AppointmentEmailContext类,如public class AppointmentEmailContext extends AbstractEmailContext<AppointmentProcessModel>{&nbsp; &nbsp;private String myAttribute;&nbsp; &nbsp; @Override&nbsp; &nbsp; public void init(final AppointmentProcessModel appointmentProcessModel, final EmailPageModel emailPageModel)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; super.init(appointmentProcessModel, emailPageModel);&nbsp; &nbsp; &nbsp; &nbsp; myAttribute = appointmentProcessModel.getMyAttribute();&nbsp; &nbsp; }&nbsp; &nbsp; public String getMyAttribute() {&nbsp; &nbsp; &nbsp; &nbsp; return myAttribute;&nbsp; &nbsp; }&nbsp; &nbsp; //...}编辑用户尚未创建 Item 类型AppointmentProcess,后来他创建了它,正如我在评论中提到的,问题已解决!!
随时随地看视频慕课网APP

相关分类

Java
我要回答