概述
動(dòng)作是Rapido當(dāng)中提供的用于實(shí)現(xiàn)將前臺(tái)數(shù)據(jù)提交給后臺(tái)處理或執(zhí)行一個(gè)Ajax調(diào)用的功能,從本質(zhì)上來說,它所完成的就是Dorado7當(dāng)中的UpdateAction與AjaxAction兩種類型Action要做的事情。動(dòng)作在定義的過程當(dāng)中,如果選擇與某實(shí)體關(guān)聯(lián),那么最終將會(huì)生成一個(gè)UpdateAction;如果不選擇與某實(shí)體關(guān)聯(lián),那么它就是一個(gè)AjaxAction。
動(dòng)作定義中,除了可以選擇具體要綁定的實(shí)體外,還允許用戶編寫B(tài)eanShell腳本與綁定若干個(gè)預(yù)先定義好的實(shí)現(xiàn)了IAction接口的實(shí)現(xiàn)類,這樣就盡可能賦予動(dòng)作最大的靈活性,在不編寫Java代碼的情況下完成足夠多的后臺(tái)復(fù)雜的業(yè)務(wù)邏輯,以進(jìn)一步增加Rapido開發(fā)復(fù)雜業(yè)務(wù)頁面的能力。
操作
切換到Rapido工作區(qū),展開動(dòng)作節(jié)點(diǎn),在需要維護(hù)動(dòng)作的包下雙擊,就可以打開動(dòng)作維護(hù)頁面,效果如下圖所示:

擴(kuò)展
前面提過,動(dòng)作定義時(shí)可以添加若干個(gè)預(yù)置的“具體動(dòng)作”,它們是一些實(shí)現(xiàn)了IAction接口的配置在Spring當(dāng)中的Java類,在Rapido當(dāng)中默認(rèn)提供了三個(gè)IAction接口實(shí)現(xiàn),分別是:
1. 根據(jù)流程模版的ID,開啟一個(gè)流程實(shí)例。
2. 保存流程任務(wù)審批過程中的審批意見信息。
3. 根據(jù)任務(wù)ID完成一個(gè)具體的流程任務(wù)。
可以看到,這三個(gè)接口實(shí)現(xiàn)都與流程相關(guān),有了這三個(gè)實(shí)現(xiàn),就可以將Rapido做的頁面與流程關(guān)聯(lián)起來,從而實(shí)現(xiàn)與流程相關(guān)業(yè)務(wù)頁面開發(fā)。IAction接口內(nèi)容如下:
package com.bstek.bdf2.rapido.action;
import java.util.Collection;
import java.util.Map;
import com.bstek.bdf2.rapido.domain.Parameter;
public interface IAction {
String getName();
Map<String,Object> execute(Map<String,Object> map);
Collection<Parameter> requiredParameters();
}
如果您需要編寫一個(gè)IAction接口實(shí)現(xiàn),那么同樣需要將實(shí)現(xiàn)類配置到Spring上下文當(dāng)中。
在編寫B(tài)eanShell腳本時(shí),除了可以使用Rapido內(nèi)置的變量外,用戶可以通過實(shí)現(xiàn)com.bstek.bdf2.bsh.VariableRegister,該接口源碼如下:
package com.bstek.bdf.bsh;
import java.util.Map;
public interface VariableRegister {
Map<String,VariableInfo> register();
}
一旦將實(shí)現(xiàn)該接口的Bean配置到Spring當(dāng)中,我們?cè)趧?dòng)作中編寫B(tài)eanShell腳本時(shí)就可以下圖所示的可用腳本變量中看到新加的BeanShell變量信息。

擴(kuò)展示例
自定義執(zhí)行存儲(chǔ)過程的BeanShell變量示例:
1.定義ProcedureTemplate對(duì)象
package com.bstek.rapido.demo;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.CallableStatementCallback;
import org.springframework.jdbc.core.CallableStatementCreator;
import com.bstek.bdf.rapido.RapidJdbcDaoSupport;
public class ProcedureTemplate extends RapidJdbcDaoSupport {
@SuppressWarnings({ "unchecked", "rawtypes" })
public Map<String, Object> call(final String procedureSql,
final Map<String, Object> param) {
final Map<String, Object> outParam = new HashMap<String, Object>();
this.getJdbcTemplate().execute(new CallableStatementCreator() {
@Override
public CallableStatement createCallableStatement(Connection con)
throws SQLException {
CallableStatement cs = con.prepareCall(procedureSql);
int i = 1;
for (String key : param.keySet()) {
Object obj = param.get(key);
if (obj instanceof String) {
int j = i++;
cs.setString(j, (String) obj);
cs.registerOutParameter(j, Types.VARCHAR);
} else if (obj instanceof Integer) {
int j = i++;
cs.registerOutParameter(j, Types.INTEGER);
cs.setInt(j, (Integer) obj);
} else if (obj instanceof Long) {
int j = i++;
cs.registerOutParameter(j, Types.INTEGER);
cs.setLong(j, (Long) obj);
}
}
return cs;
}
}, new CallableStatementCallback() {
@Override
public Object doInCallableStatement(CallableStatement cs)
throws SQLException, DataAccessException {
cs.execute();
int i = 1;
for (String key : param.keySet()) {
Object obj = param.get(key);
if (obj instanceof String) {
outParam.put(key, cs.getString(i++));
} else if (obj instanceof Integer) {
outParam.put(key, cs.getInt(i++));
} else if (obj instanceof Long) {
outParam.put(key, cs.getLong(i++));
}
}
return null;
}
});
return outParam;
}
public void execute(final String procedureSql) {
this.getJdbcTemplate().execute(procedureSql);
}
}
2.將ProcedureTemplate對(duì)象注冊(cè)為BeanShell變量
package com.bstek.rapido.demo;
import java.util.HashMap;
import java.util.Map;
import com.bstek.bdf.d7.bsh.VariableExecutor;
import com.bstek.bdf.d7.bsh.VariableInfo;
import com.bstek.bdf.d7.bsh.VariableRegister;
public class ProcedureTemplateRegister implements VariableRegister {
private ProcedureTemplate procedureTemplate;
public ProcedureTemplate getProcedureTemplate() {
return procedureTemplate;
}
public void setProcedureTemplate(ProcedureTemplate procedureTemplate) {
this.procedureTemplate = procedureTemplate;
}
@Override
public Map<String, VariableInfo> register() {
Map<String, VariableInfo> map = new HashMap<String, VariableInfo>();
VariableInfo procedureTemplateInfo = new VariableInfo();
procedureTemplateInfo.setName("procedureTemplate");
procedureTemplateInfo.setDesc("自定義的執(zhí)行存儲(chǔ)過程的ProcedureTemplate對(duì)象實(shí)例");
procedureTemplateInfo.setVariableExecutor(new VariableExecutor() {
public Object execute() {
return procedureTemplate;
}
});
map.put("procedureTemplate", procedureTemplateInfo);
return map;
}
}
3.配置到Spring配置文件中
<bean id="procedureTemplate" class="com.bstek.rapido.demo.ProcedureTemplate" />
<bean class="com.bstek.rapido.demo.ProcedureTemplateRegister">
<property name="procedureTemplate" ref="procedureTemplate" />
</bean>
4.BeanShell腳本中使用procedureTemplate變量
Map resultMap=new HashMap();
Map paramMap=new HashMap();
paramMap.put("id","123");
paramMap.put("name","beanShell");
resultMap = procedureTemplate.call("exec test_insert ?,?",paramMap);
resultMap.put("id_test",resultMap.get("id"));
return resultMap;
更多建議: