Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
Problem Statement:
We want to maintain 1-to-many data (1 feedback has multiple votes) relationship between the parent table (feedback) and child table (vote). In the feedback form, we want to use a dropdown select box instead of grids. By using a grid form element, we could have make use of Multirow Form Binder with the following configurations.
In this article, we are showing on how we can store and load data from a dropdown select box into foreign table, similar to the purpose that Multirow Form BInder serves.
Place these code into section's load and store binder using Bean Shell Form Binder.
In the section itself, place a drop down select box.
In the code example below, these are the configurations.
Panel | ||
---|---|---|
| ||
Select Box ID: team_vote Child Form ID: teamVote Child Form Foreign Key: feedback |
Load Binder - Bean Shell Form Binder
Code Block | ||||
---|---|---|---|---|
| ||||
import org.joget.apps.form.model.FormRow; import org.joget.apps.form.model.FormRowSet; import org.joget.apps.app.service.AppUtil; import org.joget.plugin.base.PluginManager; import org.joget.apps.form.model.FormLoadBinder; import org.joget.workflow.model.service.WorkflowManager; String formDefId = "teamVote"; //change this to the form id used to load grid data String foreignKey = "feedback"; //change this to the foreign key field id // Reuse Multi Row Binder to load data PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager"); WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager"); FormLoadBinder binder = (FormLoadBinder) pluginManager.getPlugin("org.joget.plugin.enterprise.MultirowFormBinder"); //Load from the grid table binder.setProperty("formDefId", formDefId); binder.setProperty("foreignKey", foreignKey); FormRowSet rows; rows = binder.load(null, "#requestParam.id#", null); String result = ""; //loop through records returned int count = 0; for (FormRow row : rows) { result += row.get("member") + ";"; count++; } if(count > 1){ result = result.substring(0, result.length() - 1); } FormRow row = new FormRow(); row.setProperty("team_vote", result); FormRowSet rowSet = new FormRowSet(); rowSet.add(row); return rowSet; |
Store Binder - Bean Shell Form Binder
Code Block | ||||
---|---|---|---|---|
| ||||
import org.joget.apps.form.model.FormRow; import org.joget.apps.form.model.FormRowSet; import org.joget.apps.app.service.AppUtil; import org.joget.plugin.base.PluginManager; import org.joget.apps.form.model.FormStoreBinder; import org.joget.workflow.model.service.WorkflowManager; import org.joget.apps.form.model.Element; import org.joget.apps.form.model.Form; import org.joget.apps.form.model.FormData; import org.joget.apps.form.service.FormUtil; String formDefId = "teamVote"; //change this to the form id used to load grid data String foreignKey = "feedback"; //change this to the foreign key field id // Reuse Multi Row Binder to load data PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager"); WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager"); FormStoreBinder binder = (FormStoreBinder) pluginManager.getPlugin("org.joget.plugin.enterprise.MultirowFormBinder"); //Load from the grid table binder.setProperty("formDefId", formDefId); binder.setProperty("foreignKey", foreignKey); Form form = FormUtil.findRootForm(element); Element field = FormUtil.findElement("team_vote", form, formData); FormRow row = rows.get(0); FormRowSet f = new FormRowSet(); f.setMultiRow(true); String vote = row.get("team_vote"); String[] votes = vote.split(";"); for(String v: votes){ if(!v.isEmpty()){ FormRow r = new FormRow (); r.setProperty("member", v); f.add(r); } } return binder.store(field, f, formData); |
...