Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
通过使用Bean Shell Form Binder,我们可以通过使用表单来加载和更新我们的环境变量值。
让我们创建一个每个文本字段的表单来表示我们的应用程序中的环境变量,并将所有的字段ID 设置为环境变量的ID。
然后,点击“属性”选项卡,然后在“高级”页面中将“加载绑定器”和“存储绑定器”设置为“Bean表单绑定器”。
使用以下脚本“加载绑定器”。
import java.util.Collection; import org.joget.apps.app.dao.EnvironmentVariableDao; import org.joget.apps.app.model.AppDefinition; import org.joget.apps.app.model.EnvironmentVariable; import org.joget.apps.app.service.AppUtil; import org.joget.apps.form.model.Element; import org.joget.apps.form.model.FormData; import org.joget.apps.form.model.FormRow; import org.joget.apps.form.model.FormRowSet; import org.joget.commons.util.LogUtil; public FormRowSet load(Element element, String primaryKey, FormData formData) { FormRowSet rows = new FormRowSet(); AppDefinition appDef = AppUtil.getCurrentAppDefinition(); if (appDef != null) { EnvironmentVariableDao environmentVariableDao = (EnvironmentVariableDao) AppUtil.getApplicationContext().getBean("environmentVariableDao"); Collection environmentVariableList = environmentVariableDao.getEnvironmentVariableList(null, appDef, null, null, null, null); //loop the result and add to FormRow if (environmentVariableList != null && environmentVariableList.size() > 0) { FormRow r = new FormRow(); for (EnvironmentVariable e : environmentVariableList) { if (e.getValue() != null) { r.setProperty(e.getId(), e.getValue()); } } rows.add(r); } } return rows; } //call load method with injected variable return load(element, primaryKey, formData);
使用以下脚本“存储绑定器”。
import org.joget.apps.app.dao.EnvironmentVariableDao; import org.joget.apps.app.model.AppDefinition; import org.joget.apps.app.model.EnvironmentVariable; import org.joget.apps.app.service.AppUtil; import org.joget.apps.form.model.Element; import org.joget.apps.form.model.FormData; import org.joget.apps.form.model.FormRow; import org.joget.apps.form.model.FormRowSet; import org.joget.apps.form.model.FormStoreBinder; import org.joget.plugin.base.PluginManager; public FormRowSet store(Element element, FormRowSet rows, FormData formData) { //check the rows is not empty before store it if (rows != null && !rows.isEmpty()) { AppDefinition appDef = AppUtil.getCurrentAppDefinition(); EnvironmentVariableDao environmentVariableDao = (EnvironmentVariableDao) AppUtil.getApplicationContext().getBean("environmentVariableDao"); //Get the submitted data FormRow row = rows.get(0); //Add / Update each Environment Variable for (Object key : row.keySet()) { String envId = (String) key; String value = row.getProperty(envId); if (!envId.isEmpty()){ EnvironmentVariable e = environmentVariableDao.loadById(envId, appDef); if (e != null) { e.setValue(value); environmentVariableDao.update(e); } else { EnvironmentVariable e = new EnvironmentVariable(); e.setAppDefinition(appDef); e.setId(envId); e.setValue(value); environmentVariableDao.add(e); } } } } return rows; } //call store method with injected variable return store(element, rows, formData);
以下为结果表单
本文的示例应用可以从此下载 APP_update_env-1-20151027104612.jwa.