Activiti - 如何从扩展 EnumFormType 的自定义表单类型中获取信息,例如 "values"?
Activiti - How do you get the information, such as "values", from a custom form type that extends EnumFormType?
我创建了一个扩展 EnumFormType
的自定义表单类型,我认为我可以使用方法 getInformation("values")
但它 returns null
.基本上我需要能够在 Activiti designer for eclipse 中获取以 属性 window 形式设置的值。
我的自定义表单类型:
import java.util.Map;
import org.activiti.engine.impl.form.EnumFormType;
public class ImpactedSitesFormType extends EnumFormType {
private static final long serialVersionUID = 1L;
public static final String TYPE_NAME = "impactedSite";
public ImpactedSitesFormType() {
this(null);
}
public ImpactedSitesFormType(Map<String, String> values) {
super(values);
// TODO Auto-generated constructor stub
}
public String getName() {
return TYPE_NAME;
}
public Object convertFormValueToModelValue(String propertyValue) {
Integer impactedSite = Integer.valueOf(propertyValue);
return impactedSite;
}
public String convertModelValueToFormValue(Object modelValue) {
if (modelValue == null) {
return null;
}
return modelValue.toString();
}
}
我的JSP代码:
<c:if test="${type == 'impactedSite'}">
<select name="${property.getId()}">
<c:forEach var="entry" items='${property.getType().getInformation("values")}'>
<option value="${entry.key}">${entry.value}</option>
</c:forEach>
</select><br /><br />
</c:if>
我 运行 今天遇到了同样的问题——这是我的两分钱:
很可能,您正在 activiti.cfg.xml
中注册您的自定义类型,例如:
<property name="customFormTypes">
<list>
<bean class="org.yourdomain.ImpactedSitesFormType" />
...
</list>
</property>
对吧?这将使用默认构造函数创建一个实例,您可以在其中将值显式设置为 null
.
不幸的是,无法鼓励 Activiti 调用您的其他构造函数。相反,您必须使用自定义 FormTypes
实现并手动进行初始化:
public class CustomFormTypes extends FormTypes {
public CustomFormTypes() {
// register Activiti's default form types
addFormType(new StringFormType());
addFormType(new LongFormType());
addFormType(new DateFormType("dd/MM/yyyy"));
addFormType(new BooleanFormType());
addFormType(new DoubleFormType());
}
@Override
public AbstractFormType parseFormPropertyType(FormProperty formProperty) {
if (ImpactedSitesFormType.TYPE_NAME.equals(formProperty.getType())) {
Map<String, String> values = new LinkedHashMap<>();
for (FormValue formValue : formProperty.getFormValues()) {
values.put(formValue.getId(), formValue.getName());
}
return new ImpactedSitesFormType(values);
} else {
// delegate construction of all other types
return super.parseFormPropertyType(formProperty);
}
}
}
要让 Activiti 知道您的 CustomFormTypes
class,请在 activiti.cfg.xml
中配置它:
<property name="formTypes">
<bean class="org.yourdomain.CustomFormTypes" />
</property>
This blog post and its example code on GitHub帮了我大忙!
我创建了一个扩展 EnumFormType
的自定义表单类型,我认为我可以使用方法 getInformation("values")
但它 returns null
.基本上我需要能够在 Activiti designer for eclipse 中获取以 属性 window 形式设置的值。
我的自定义表单类型:
import java.util.Map;
import org.activiti.engine.impl.form.EnumFormType;
public class ImpactedSitesFormType extends EnumFormType {
private static final long serialVersionUID = 1L;
public static final String TYPE_NAME = "impactedSite";
public ImpactedSitesFormType() {
this(null);
}
public ImpactedSitesFormType(Map<String, String> values) {
super(values);
// TODO Auto-generated constructor stub
}
public String getName() {
return TYPE_NAME;
}
public Object convertFormValueToModelValue(String propertyValue) {
Integer impactedSite = Integer.valueOf(propertyValue);
return impactedSite;
}
public String convertModelValueToFormValue(Object modelValue) {
if (modelValue == null) {
return null;
}
return modelValue.toString();
}
}
我的JSP代码:
<c:if test="${type == 'impactedSite'}">
<select name="${property.getId()}">
<c:forEach var="entry" items='${property.getType().getInformation("values")}'>
<option value="${entry.key}">${entry.value}</option>
</c:forEach>
</select><br /><br />
</c:if>
我 运行 今天遇到了同样的问题——这是我的两分钱:
很可能,您正在 activiti.cfg.xml
中注册您的自定义类型,例如:
<property name="customFormTypes">
<list>
<bean class="org.yourdomain.ImpactedSitesFormType" />
...
</list>
</property>
对吧?这将使用默认构造函数创建一个实例,您可以在其中将值显式设置为 null
.
不幸的是,无法鼓励 Activiti 调用您的其他构造函数。相反,您必须使用自定义 FormTypes
实现并手动进行初始化:
public class CustomFormTypes extends FormTypes {
public CustomFormTypes() {
// register Activiti's default form types
addFormType(new StringFormType());
addFormType(new LongFormType());
addFormType(new DateFormType("dd/MM/yyyy"));
addFormType(new BooleanFormType());
addFormType(new DoubleFormType());
}
@Override
public AbstractFormType parseFormPropertyType(FormProperty formProperty) {
if (ImpactedSitesFormType.TYPE_NAME.equals(formProperty.getType())) {
Map<String, String> values = new LinkedHashMap<>();
for (FormValue formValue : formProperty.getFormValues()) {
values.put(formValue.getId(), formValue.getName());
}
return new ImpactedSitesFormType(values);
} else {
// delegate construction of all other types
return super.parseFormPropertyType(formProperty);
}
}
}
要让 Activiti 知道您的 CustomFormTypes
class,请在 activiti.cfg.xml
中配置它:
<property name="formTypes">
<bean class="org.yourdomain.CustomFormTypes" />
</property>
This blog post and its example code on GitHub帮了我大忙!