How to load data dynamically in ListBox of Task Form or Process Form in jBPM
We would be using "jBPM-7.33.0.Final" version for this example.
We can achieve this using Data Providers. Specifically, we need to create a class that implements
"org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider" Interface.
When the Field type attribute for the form field is configured as ListBox we have to implement a custom data provider class that implements SelectorDataProvider Interface.
The implementation class of SelectorDataProvider needs to implement below two methods from the SelectorDataProvider.
1. public String getProviderName()
- It returns the Provider name of the implementation class which will be used in the attribute "Data Provider" of the ListBox Form field.
2. public SelectorData getSelectorData(FormRenderingContext context)
- Using this method we can add the values which we need to load or display in the ListBox form field of Task Form or Process Form.
Implementation Class for SelectorDataProvider
package org.jbpm.formModeler.examples.providers;
import java.util.HashMap;
import java.util.Map;
import javax.enterprise.context.Dependent;
import org.kie.workbench.common.forms.dynamic.model.config.SelectorData;
import org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider;
import org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext;
@Dependent
public class MyDataSelectorProvider implements SelectorDataProvider {
public String getProviderName() {
return "myProvider";
}
public SelectorData getSelectorData(FormRenderingContext arg0) {
SelectorData<String> selectorData = new SelectorData<String>();
Map<String, String> states = new HashMap<String, String>();
states.put("Delhi", "Delhi");
states.put("Maharashtra", "Maharashtra");
states.put("Gujrat", "Gujrat");
selectorData.setValues(states);
return selectorData;
}
}
We have to create an empty jBPM maven project in IDE of your choice and need to put this class inside that project.Here is the screenshot of the project structure.
Create a file "ErraiAPP.properties" inside the META-INF directory of the project and add below property inside this file without quotes.
"errai.marshalling.mappingAliases=org.jboss.errai.databinding.client.MapBindableProxy->java.util.Map"
Create an empty beans.xml file inside META-INF Directory.
Once above steps finished building the project using command "mvn clean install" and it should generate the .jar file inside the target directory.
Copy-paste the generated jar from target directory to location "business-central.war/WEB-INF/lib" directory.
We also need errai data binding jar in the lib directory so place the "errai-data-binding-${VERSION}.Final.jar" to location "business-central.war/WEB-INF/lib"
Create a project if not created in the business central and add the form asset and drag the ListBox on the created form.

Add the properties for the ListBox like name, Label, and most importantly the Field Binding and map the appropriate field binding to the appropriate Data Objects or other variables.
Download the project from Business Central to your file system by clicking on any asset and then click the setting gear icon in the project explorer at the top right corner.
Once the project is downloaded in the local file system go to $PROJECT_NAME/src/main/resources/path/to/form/StateCityListForm.frm file and open this .frm file in any text editor and search for property "dataProvider" which is empty and it doesn't have value. You have to give the value of the custom data provider class which we have created above. Please note that you have to give fully qualified class name.
So, the dataProvider property should look like in .frm file:
"dataProvider" : "org.jbpm.formModeler.examples.providers.MyDataSelectorProvider",
After the above modification save it and again we have to reimport the project in the Business Central.
Go to the project folder where your pom.xml is located and execute below git commands
- git init .
- git add .
- git commit -m "commit message"
After that copy the path till $PROJECT_NAME directory and go to the Business Central and import the project by Clicking the import project Option from the dropdown.
After clicking the import project option one popup window would open paste your project location inside the text box and click on the import button.
Once the project is imported build and deploy it and create a process instance of the process and you should be able to see the data dynamically loaded inside the ListBox of the Process or Task Form whichever you have created.
Please note that I have used Wildfly Application Server 14 also known as JBoss EAP for jBPM installation and deployment.
Hi, this is so helpful. however i'm getting below error while i open form to start process.
ReplyDeletePlease help to resolve this.
16:26:37,503 ERROR [io.undertow.request] (default task-11) UT005023: Exception handling request to /business-central/out.41199-27876.erraiBus: org.jboss.errai.marshalling.client.api.exceptions.MarshallingException: Failed to demarshall an instance of org.kie.workbench.common.forms.dynamic.service.shared.impl.MapModelRenderingContext
at org.jboss.errai.marshalling.server.marshallers.DefaultDefinitionMarshaller.demarshall(DefaultDefinitionMarshaller.java:180)
at org.jboss.errai.marshalling.client.marshallers.AbstractCollectionMarshaller.marshallToCollection(AbstractCollectionMarshaller.java:89)
at org.jboss.errai.marshalling.client.marshallers.ListMarshaller.doDemarshall(ListMarshaller.java:47)
at org.jboss.errai.marshalling.client.marshallers.ListMarshaller.doDemarshall(ListMarshaller.java:34)
at org.jboss.errai.marshalling.client.marshallers.AbstractCollectionMarshaller.doDemarshall(AbstractCollectionMarshaller.java:48)
at org.jboss.errai.marshalling.client.marshallers.AbstractCollectionMarshaller.doDemarshall(AbstractCollectionMarshaller.java:33)
at org.jboss.errai.marshalling.client.marshallers.AbstractBackReferencingMarshaller.demarshall(AbstractBackReferencingMarshaller.java:76)
at org.jboss.errai.marshalling.client.marshallers.ErraiProtocolEnvelopeMarshaller.doDemarshall(ErraiProtocolEnvelopeMarshaller.java:68)
at org.jboss.errai.marshalling.client.marshallers.ErraiProtocolEnvelopeMarshaller.demarshall(ErraiProtocolEnvelopeMarshaller.java:39)
at org.jboss.errai.bus.server.io.MessageFactory.getParts(MessageFactory.java:152)
at org.jboss.errai.bus.server.io.MessageFactory.createCommandMessage(MessageFactory.java:101)
...
...
...
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:370)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: marshalled type is unknown to the marshalling framework: org.jboss.errai.databinding.client.MapBindableProxy
at org.jboss.errai.marshalling.client.marshallers.ObjectMarshaller.demarshall(ObjectMarshaller.java:85)
Request to please help me to resolve it. many thanks