Search code examples
javajbossjbpmbusiness-process-management

Populate dynamic values into JBPM select box


I had tried implementing org.jbpm.formModeler.core.config.SelectValuesProvider and compiled my code and created a jar , also include a blank bean.xml in "/src/main/resources/META-INF"

Added the jar in JBPM classpath but i couldn't able to see anything listed in the jbpm data provider combo box.

My code is given below :

    import org.jbpm.formModeler.api.client.FormRenderContext;
    import org.jbpm.formModeler.api.model.Field;
    import org.jbpm.formModeler.api.model.RangeProvider;
    import org.jbpm.formModeler.core.config.SelectValuesProvider;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.HashMap;
    import java.util.Locale;
    import java.util.Map;

    public class ProductRangeProvider implements SelectValuesProvider {

        @Override
        public String getIdentifier() {

            String identiferName = "deparmnet";
            return identiferName;
        }

        @Override
        public Map<String, String> getSelectOptions(Field field, String currentValue,
                FormRenderContext formDetails, Locale locale) {
            Map<String, String> maps = new HashMap<String, String>();
            String employee = ""; 
            String department = "";
            String DbIp = "jdbc:mysql://*********:*****/****";
            String userName = "***";
            String password = "****";
            Connection con=null;
            try{
                Class.forName("com.mysql.jdbc.Driver");
                con=DriverManager.getConnection(DbIp,userName,password);
                PreparedStatement stmt=con.prepareStatement("Select role from role_master");
                ResultSet rs=stmt.executeQuery();

                while(rs.next()){
                    maps.put(rs.getString(1), rs.getString(1));
                }
                con.close();
            }
            catch(Exception E){
                System.out.println(E);
            }
            finally {
                try {
                    con.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return maps;

        }
    }

Is there any configuration required for JBPM to identify my class just like workitemHandler definition .?


Solution

  • Try adding jar file in class path. This will resolve the issue .