Hi all,

I am building an application, and one of the requirements is to be able to populate a Select Box list from the results of a RESTful API call.

I have done as much research as I can, and it seems the solution is to create a Form Binder plugin, which does the RESTful call in normal Java code, returning the list of data.

Following information found here I have created a class which extends FormBinder, and implements FormLoadElementBinder. I successfully compiled, and imported this plugin into Joget, using the plugin importer found in the settings menu. The upload was successful, and the plugin displayed in the list of plugins with the correct name.

It is now that I am stuck though. How do I go about using this plugin, so that when a user clicks on the Select Box, the options returned via the REST call are there? I have tried reading as much documentation as I can find, but none seem to explain it in depth.

I can't find where I associate my plugin with a Select Box in Joget, so that the Select Box uses my java code to get the data to display. I tried searching in all of the options in the form-builder, but cannot find anywhere.

I would greatly appreciate any feedback, or to point me in the direction of the proper way to achieve what I need.

Thanks a lot,
Troy.

  • No labels

1 Comment

  1. I have solved the problem, and will describe how for any other people wanting to do the same.

    So I was using the wrong class first. To populate a field, you need to extend FormOptionsBinder, and implement FormLoadBinder.

    Implement the required method such as getVersion(), getName() as standard. Now the data comes from the load() function, with an example implemented below.

    	@Override
    	public FormRowSet load(Element arg0, String arg1, FormData arg2) {
    		// Each piece of data has a label and value. The label is visible to the user, and the ID is used internally
    		String[] ids = 			{"234", "4532432", "213231", "123123"};
    		String[] usernames = 	{"Troy", "Jim", "Bob", "Tim"};
    
    		FormRowSet userSet = new FormRowSet();
    
    		for (int i = 0; i < ids.length; i++) {
    			FormRow month = new FormRow();
    			month.put(FormUtil.PROPERTY_LABEL, usernames[i]);
    			month.put(FormUtil.PROPERTY_VALUE, ids[i]);
    			userSet.add(month);
    		}
    
    		return userSet;
    	}

    You can get the data from anywhere, including a REST call, SOAP calls, etc.

    Finally build the plugin using the normal pom.xml file generated by Joget. Import the plugin in the usual way (from the settings menu on the main Joget site). Now create whatever form element you want in the form-builder. In the "edit" menu of your element, click the "Or Choose Options Binder" dropdown, and you should find your plugin, identified by the name you gave it in Java.

    Your form element now should be populated by the code you defined in your load() method.