Hi, sorry for the delay.. so let's start (be prepared for a long email)
the process is kind of similar as the old form modeler but there's a small "hack" on the form you want to use the DataProvider so the steps are:
1.- Create a MVN project with your favourite IDE and add at least this deps (mvn might ask for more, but I think this are the minimum):
<dependency>
<groupId>org.kie.workbench.forms</groupId>
<artifactId>kie-wb-common-forms-api</artifactId>
<version>{kie.version}</version>
</dependency>
<dependency>
<groupId>org.kie.workbench.forms</groupId>
<artifactId>kie-wb-common-dynamic-forms-api</artifactId>
<version>{kie.version}</version>
</dependency>
2.- Create a class that implements org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider. This interface is providing two methods:
- String getProviderName() -> Should return the name for the provider... due to an issue pending to solve in your implementation it should return your className :S
- SelectorData getSelectorData(FormRenderingContext context) -> this is the method that is going to provide the data for your selector, so all your magic should be done here.
The method receives a FormRenderingContext param that basically has all the information about the current form rendering. You can get the current form from therer, the model bound to the form to read the status of it... etc.
Whatever you do here this method should return an instance of SelectorData<T> containing:
- A Map<T, String> values -> containing the selectionr options. key (T) should be the real value of the option on the dropdown and the value (String) should be the text that is going to be displayed on the dropdown/radio
- A T selectedValue -> specifying which is the selected value if the field has no value comming from the bound model. This is optional.
Note that the type T has to match the data type of the model property bound to the field... for example if you have a ListBox bound to a String property on a Data Object (or variable on a process) you should return a SelectorData<String> other than that might cause problems and data won't be loaded.
3.- Configure CDI (IMPORTANT!!!)
- Add a CDI scope to your SelectorDataProvider, @Dependent should be enough but use the one that makes sense for your design
- On your project create a META-INF folder on src/main/resources and place inside a empty beans.xml file
With this 3 steps done you're ready to publish your SDP, so build your jar file and place it on the Web-inf/lib folder of your deployed .war folder.
Now let's configure hack your form, please don't do this at home :)
1.- Clone the repo that contains your form
2.- Locate your form and edit it, that's a one line JSON file... in your IDE do a code reformat to make it look better (make a backup copy of your form for security!!)
3.- Locate your field on the form, it should look similar to this:
{
"options": [],
"dataProvider": "",
"id": {anyID},
"name": {anyName},
"label": {anyLabel},
"required": false,
"readOnly": false,
"validateOnChange": true,
"binding": {anyBinding},
"standaloneClassName": "java.lang.String",
"code": "ListBox",
"serializedFieldClassName": "org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.StringListBoxFieldDefinition"
}
4.- On the "dataProvider" property you should write the following "remote:<your SelectorDataProvider className>", so it should be something like:
{
"options": [],
"dataProvider": "remote:org.jbpm.demo.MySelectorDataProvider",
"id": {anyID},
"name": {anyName},
"label": {anyLabel},
"required": false,
"readOnly": false,
"validateOnChange": true,
"binding": {anyBinding},
"standaloneClassName": "java.lang.String",
"code": "ListBox",
"serializedFieldClassName": "org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.listBox.definition.StringListBoxFieldDefinition"
}
Note that if there are options on the field configuration the forms engine won't call your SelectorDataProvider, so clean them if you have some.
5.- Save changes, commit & push the changes back to the repo.
Just a reminder, you should be cautious doing this forms modifications manually...
Ok, so now you should be free to start your server and se your code running, I'd recommend you doing a fake implementation at first and debug a little before doing the final implementation.
That's all, I hope it helps and and let me know how it goes. I you need more help you know where to find me.
Regards,
Pere