Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To develop a Multi Store binder, we will need the JDBC connection setting and also the custom query to store the form data based the collected form dataa multi-selector in a grid form and a text editor for additional notes for app designers.

  1. Binders: Displays a list of store binders available.


  2. Comments: Additional notes users might wish to add.


...

Code Block
languagejava
titleImplementation of all basic abstract methods
linenumberstrue
collapsetrue
package org.joget.tutorial;
 
import org.joget.apps.app.service.AppPluginUtil;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model.FormBinder;
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.form.model.FormStoreBinder;
import org.joget.apps.form.model.FormStoreElementBinder;
import org.joget.apps.form.model.FormStoreMultiRowElementBinder;
 
public class JdbcStoreBinder extends FormBinder implements FormStoreBinder, FormStoreElementBinder, FormStoreMultiRowElementBinder {
    
    private final static String MESSAGE_PATH = "messages/JdbcStoreBindermultiStoreBinder";
    
    public String getName() {
        return "JDBCMulti Store Binder";
    }
 
    public String getVersion() {
        return "57.0.0";
    }
    
    public String getClassName() {
        return getClass().getName();
    }
 
    public String getLabel() {
        //support i18n
        return AppPluginUtil.getMessage("org.joget.tutorial.JdbcStoreBinderMultiStoreBinder.pluginLabel", getClassName(), MESSAGE_PATH);
    }
    
    public String getDescription() {
        //support i18n
        return AppPluginUtil.getMessage("org.joget.tutorial.JdbcStoreBinderMultiStoreBinder.pluginDesc", getClassName(), MESSAGE_PATH);
    }
 
    public String getPropertyOptions() {
        return AppUtil.readPluginResource(getClassName(), "/properties/jdbcStoreBindermultiStoreBinder.json", null, true, MESSAGE_PATH);
    }
 
    public FormRowSet store(Element element, FormRowSet rows, FormData formData) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}

Then, we have to do a UI for admin user to provide inputs for our plugin. In getPropertyOptions method, we already specify our Plugin Properties Options definition file is locate located at "/properties/jdbcStoreBindermultiStoreBinder.json". Let us create a directory "resources/properties" under "jdbcmulti_store_binder/src/main" directory. After create creating the directory, create a file named "jdbcStoreBindermultiStoreBinder.json" in the "properties" folder.

...

Code Block
languagejs
linenumberstrue
[
    {
        "title" : '@@form"@@plugin.jdbcStoreBindermultistorebinder.config@@'",
        "properties" : [{
        name  : 'jdbcDatasource',  {
        label : '@@form.jdbcStoreBinder.datasource@@',
       "name" type : 'selectbox'"binders",
        options : [{
            value"label" : 'custom'"@@plugin.multistorebinder.storeBinder@@",
            label : '@@form.jdbcStoreBinder.customDatasource@@'
  "type" : "elementmultiselect",
    },{
            value : 'default',
            label : '@@form.jdbcStoreBinder.defaultDatasource@@'
        }],
        value : 'default'
    },{
        name : 'jdbcDriver',
        label : '@@form.jdbcStoreBinder.driver@@',
        description : '@@form.jdbcStoreBinder.driver.desc@@',
        type : 'textfield',
        value : 'com.mysql.jdbc.Driver',
        control_field: 'jdbcDatasource',
        control_value: 'custom',
        control_use_regex: 'false',
        required : 'true'
    },{
        name : 'jdbcUrl',
        label : '@@form.jdbcStoreBinder.url@@',
        type : 'textfield',
        value : 'jdbc:mysql://localhost/jwdb?characterEncoding=UTF8',
        control_field: 'jdbcDatasource',
        control_value: 'custom',
        control_use_regex: 'false',
        required : 'true'
    },{
        name : 'jdbcUser',
        label : '@@form.jdbcStoreBinder.username@@',
        type : 'textfield',
        control_field: 'jdbcDatasource',
        control_value: 'custom',
        control_use_regex: 'false',
        value : 'root',
        required : 'true'
    },{
        name : 'jdbcPassword',
        label : '@@form.jdbcStoreBinder.password@@',
        type : 'password',
        control_field: 'jdbcDatasource',
        control_value: 'custom',
        control_use_regex: 'false',
        value : ''
    },{
        name : 'check_sql',
        label : '@@form.jdbcStoreBinder.check_sql@@',
        description : '@@form.jdbcStoreBinder.check_sql.desc@@',
        type : 'codeeditor',
        mode : 'sql',
        required : 'true'
    },{
        name : 'insert_sql',
        label : '@@form.jdbcStoreBinder.insert_sql@@',
        description : '@@form.jdbcStoreBinder.insert_sql.desc@@',
        type : 'codeeditor',
        mode : 'sql',
        required : 'true'
    },{
        name : 'update_sql',
        label : '@@form.jdbcStoreBinder.update_sql@@',
        description : '@@form.jdbcStoreBinder.update_sql.desc@@',
        type : 'codeeditor',
        mode : 'sql',
        required : 'true'
    },{
        name : 'delete_sql',
        label : '@@form.jdbcStoreBinder.delete_sql@@',
"options_ajax" : "[CONTEXT_PATH]/web/property/json/getElements?classname=org.joget.apps.form.model.FormStoreBinder&exclude=org.joget.sample.MultiStoreBinder",
                description"url" : '@@form.jdbcStoreBinder.delete_sql.desc@@'"[CONTEXT_PATH]/web/property/json[APP_PATH]/getPropertyOptions",
        type : 'codeeditor',
        mode : 'sql'"default_property_values_url" : "[CONTEXT_PATH]/web/property/json[APP_PATH]/getDefaultProperties",
        required : 'true'
    }],
    buttons"required" : [{"true"
        name : 'testConnection',    
  },{
      label : '@@form.jdbcStoreBinder.testConnection@@',
        ajax_url : '[CONTEXT_PATH]/web/json/app[APP_PATH]/plugin/org.joget.tutorial.JdbcStoreBinder/service?action=testConnection',
"name" : "comment",
             fields : ['jdbcDriver', 'jdbcUrl', 'jdbcUser', 'jdbcPassword'] "label" : "@@plugin.multistorebinder.comment@@",
        control_field: 'jdbcDatasource',
       "type" control_value: 'custom',"codeeditor"
        control_use_regex: 'false'    }
    }    ]
    }
]

Same as JDBC Options Binder, we will need to add a test connection button for custom JDBC setting. Please refer to How to develop a JDBC Options Binder on the Web Service Plugin implementation.

...