码迷,mamicode.com
首页 > 其他好文 > 详细

Activiti 使用小结

时间:2014-11-28 17:49:51      阅读:354      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   使用   sp   

自定义表单类型

使用动态表单,需要定义表单的字段以及属性,在WEB流程设计器中没有Default字段(Eclipse中有),给设计带来了一定的困难,下面介绍如何在WEB流程设计器中扩展表单。

首先在stencilset.json文件中添加扩展类型,添加的位置就是formproperty_type下,将会出现在下拉框中

{

"id" : "formproperty_type",

"name" : "Type",

"name_de" : "Typ",

"type" : "Choice",

"value" : "",

"width" : 100,

"optional" : false,

"items" : [ {

"id" : "c1",

"title" : "String",

"title_de" : "String",

"value" : "string",

"refToView" : ""

}, {

"id" : "c2",

"title" : "Date",

"title_de" : "Date",

"value" : "date",

"refToView" : ""

}, {

"id" : "c3",

"title" : "Long",

"title_de" : "Long",

"value" : "long",

"refToView" : ""

}, {

"id" : "c4",

"title" : "Boolean",

"title_de" : "Boolean",

"value" : "boolean",

"refToView" : ""

}, {

"id" : "c5",

"title" : "Enum",

"title_de" : "Enum",

"value" : "enum",

"refToView" : ""

}, {

"id" : "c6",

"title" : "SmartRef",

"title_de" : "SmartRef",

"value" : "smartref",

"refToView" : ""

}, {

"id" : "c7",

"title" : "Group",

"title_de" : "Group",

"value" : "group",

"refToView" : ""

}

]

}

?

bubuko.com,布布扣

?

构建自定义的GroupFormType,如果只要一般的扩展,则不用对加入values

public class GroupFormType extends AbstractFormType

{

????protected Map<String, String> values;

????public GroupFormType(){}

????public GroupFormType(Map<String, String> values)

????{

????????this.values = values;

????}

????@Override

????public String getName()

????{

????????return ActivitiConstants.GROUP_TYPE;

????}

????@Override

????public Object convertFormValueToModelValue(String propertyValue)

????{

????????return propertyValue;

????}

????@Override

????public String convertModelValueToFormValue(Object modelValue)

????{

????????return modelValue == null ? null : modelValue.toString();

????}

????@Override

????public Object getInformation(String key)

????{

????????if (ActivitiConstants.VALUES_KEY.equals(key))

????????{

????????????return values;

????????} else

????????{

????????????return null;

????????}

????}

}

?

扩展FormTypes,使得自定义类型能够处理FormValues

public class CustomFormTypes extends FormTypes

{

????@Override

????public AbstractFormType parseFormPropertyType(FormProperty formProperty)

????{

????????if (ActivitiConstants.GROUP_TYPE.equals(formProperty.getType()))

????????{

????????????Map<String, String> values = new LinkedHashMap<String, String>();

????????????for (FormValue formValue : formProperty.getFormValues())

????????????{

????????????????values.put(formValue.getId(), formValue.getName());

????????????}

????????????return new GroupFormType(values);

????????} else if (ActivitiConstants.SMART_REF_TYPE.equals(formProperty.getType()))

????????{

????????????Map<String, String> values = new LinkedHashMap<String, String>();

????????????for (FormValue formValue : formProperty.getFormValues())

????????????{

????????????????values.put(formValue.getId(), formValue.getName());

????????????}

????????????return new SmartRefFormType(values);

????????} else

????????{

????????????return super.parseFormPropertyType(formProperty);

????????}

?

????}

}

?

在流程引擎参数中设置,需要注意的是,如果扩展了FormTypes,则需要把所有的类型都加入到参数中(包括自带类型),否则会报找不到类型

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">

<property name="formTypes">

<bean class="com.pera.dwf.web.activiti.formtype.CustomFormTypes" />

</property>

<property name="customFormTypes">

<list>

<bean class="org.activiti.engine.impl.form.StringFormType" />

<bean class="org.activiti.engine.impl.form.LongFormType" />

<bean class="org.activiti.engine.impl.form.DateFormType">

????<constructor-arg value="yyyy-MM-dd" />

</bean>

<bean class="org.activiti.engine.impl.form.BooleanFormType" />

<bean class="com.pera.dwf.web.activiti.formtype.GroupFormType"></bean>

<bean class="com.pera.dwf.web.activiti.formtype.SmartRefFormType"></bean>

</list>

</property>

?

经过处理后,最终的动态表单的返回值,可以得到FormValues的值

0: ?

{

infos:?

{

5ef89d50-95ff-4e33-8aa1-48df354c6c52:?"不合格品文档"

}

-

fp:?

{

id:?"Excel1"

name:?"不合格品文档"

type:?

{

name:?"smartref"

}

-

value:?null

required:?false

writable:?true

readable:?true

}

-

}

?

Activiti 使用小结

标签:style   blog   http   io   ar   color   os   使用   sp   

原文地址:http://www.cnblogs.com/shm10/p/4105245.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!