求教 jbpm4.4动态控制表单域访问怎么实现??
nxj1980
2011-06-24
在网上看到例子,使用controller-》variable -》-access设置 <task assignee="#{owner}" form="/html/resourceForm.jsp" g="122,174,92,52" name="申请"> <transition g="-71,-17" name="to 主管审批" to="主管审批"/> <controller> <variable access="read,write" name="userId"/> <variable access="read,write" name="title"/> <variable access="read,write" name="day"/> <variable access="read,write" name="reason"/> <variable access="read,write" name="leaveTime"/> <variable access="read" name="prop0"/> </controller> </task>
//根据任务实例,以及变量的名称,判断这个变量是否能够被当前用户修改 public static String attr(TaskInstance ti,String propertyName){ TaskController tc = ti.getTask().getTaskController(); if(tc != null){ List accesses = tc.getVariableAccesses(); for (Iterator iterator = accesses.iterator(); iterator.hasNext();) { VariableAccess va = (VariableAccess)iterator.next(); if(va.getVariableName().equals(propertyName)){ Access access = va.getAccess(); if(access.isWritable()){ return ""; } } } } //默认不可修改 return "disabled"; }
|
|
nxj1980
2011-06-24
控制表单域的意思就是在不同的环节,根据参与人在流程中的角色不同,来动态设置表单域的只读或者干脆不显示
|
|
nxj1980
2011-06-24
用户指南之类的文档我都翻了好几遍了,仍没找到解决办法
|
|
nxj1980
2011-06-24
哪位高手能给个思路也好
|
|
comsci
2011-06-28
楼主的帖子的名称好像有问题,是否是动态?
|
|
nxj1980
2011-06-28
就是在流程定义阶段确定表单域的访问控制,在运行阶段应用这些定义好的控制
最终实现例如: 某个环节可以填写表单中的前三项,下一环节只可以填后两项、并且可以看到其它项的值 |
|
nxj1980
2011-06-28
对,标题写错了,应该是动态
|
|
comsci
2011-07-01
nxj1980 写道 就是在流程定义阶段确定表单域的访问控制,在运行阶段应用这些定义好的控制
最终实现例如: 某个环节可以填写表单中的前三项,下一环节只可以填后两项、并且可以看到其它项的值 流程定义阶段的访问控制需要用户在运行JBPM的之前,为此编写控制器代码,JBPM里面不带这种模块 |
|
nxj1980
2011-07-02
我实现了,是使用了两个任务变量将访问控制保存起来,再在流程执行时取得这两个变量
流程定义: <?xml version="1.0" encoding="UTF-8"?> <process name="请假流程" xmlns="http://jbpm.org/4.4/jpdl"> <start g="148,76,48,48" name="start1"> <transition g="-47,-17" name="to 申请" to="申请"/> </start> <task assignee="#{owner}" form="/html/resourceForm.jsp" g="122,174,92,52" name="申请"> <transition g="-71,-17" name="to 主管审批" to="主管审批"/> <variable name="_access_read_write" type="string" init-expr="userId,title,day,reason,leaveTime,prop0"/> </task> <task assignee="#{owner}" form="/html/resourceForm.jsp" g="120,273,92,52" name="主管审批"> <transition g="-95,-17" name="to 判断请假时间" to="判断请假时间"/> <variable name="_access_read_write" type="string" init-expr="userId,title,day,reason,leaveTime"/> <variable name="_access_read" type="string" init-expr="prop0"/> </task> <decision expr="#{day > 3 ? 'to 副总审批' : 'to 人事处理'}" g="144,380,48,48" name="判断请假时间"> <transition g="-71,-17" name="to 人事处理" to="人事处理"/> <transition g="-71,-17" name="to 副总审批" to="副总审批"/> </decision> <task assignee="#{owner}" form="/html/resourceForm.jsp" g="125,476,92,52" name="人事处理"> <transition g="-47,-17" name="to end1" to="end1"/> <variable name="_access_read_write" type="string" init-expr="userId,title,day,reason,leaveTime,prop0,prop1"/> <variable name="_access_read" type="string" init-expr="prop0"/> </task> <task assignee="#{owner}" form="/html/resourceForm.jsp" g="295,394,92,52" name="副总审批"> <transition g="-47,-17" name="to end1" to="end1"/> <variable name="_access_read_write" type="string" init-expr="userId,title,day,reason,leaveTime"/> </task> <end g="173,621,48,48" name="end1"/> </process> 取得访问控制: /** * 根据任务与表单主键返回对应表单 * @param task * @param formId * @return */ public Form getTaskForm(TaskImpl task,String formId){ if (task.getFormResourceName()==null){ task = this.getTask(task.getId()); } String access_read_write = (String)task.getVariable("_access_read_write"); String access_read = (String)task.getVariable("_access_read"); Form form = this.formMng.findById(formId); form.setContent(setFormFieldAccess(form,access_read_write,access_read)); SessionFactoryUtil.evict(form); return form; } /** * 设置表单访问控制 * @param form * @param access_read_write * @param access_read * @return */ private String setFormFieldAccess(Form form,String access_read_write,String access_read){ String jsonContent = form.getContent(); Set formFields = form.getFormFields(); String[] rwArray = access_read_write==null?new String[0]:access_read_write.split(","); String[] rArray = access_read==null?new String[0]:access_read.split(","); //设置只读表单域 for(String r : rArray){ jsonContent = jsonContent.replaceAll("entityProperty : \""+r+"\"", "entityProperty : \""+r+"\",readOnly : true"); } //设置隐藏表单域 long newLength = rwArray.length+rArray.length; if (newLength>0){ String[] tempArray =new String[rwArray.length+rArray.length]; System.arraycopy(rwArray, 0, tempArray,0, rwArray.length); System.arraycopy(rArray, 0, tempArray,rwArray.length, rArray.length); Iterator formFieldsIt = formFields.iterator(); while(formFieldsIt.hasNext()){ FormField formField = (FormField)formFieldsIt.next(); int i=0; for(i=0;i<tempArray.length;i++){ if (tempArray[i].equals(formField.getCode())){ break; } } if (i==tempArray.length){ jsonContent = jsonContent.replaceAll("entityProperty : \""+formField.getCode()+"\"", "entityProperty : \""+formField.getCode()+"\",hidden : true,hideLabel : true "); } } } return jsonContent; } |
|
comsci
2011-07-04
严格来讲,这种对外部表单数据的访问控制不属于JBPM本身应该关注的东西。。。
|