Greetings!

I'm using the community Edition for Joget. I'd like to know what would be the correct way to do a Dynamic cascading drop-down list, but using the Bean Shell Form Binder.

I've try to do so, but I'm not sure I'm using the query in a good way.

For example if I have my query like: "SELECT id, description, cod_materia FROM matriz.mat_motivo_tbl"

I believe the id will be the value, the description the label and the cod_materia de grouping column, also I'm using the option for "Field ID to control available options based on Grouping". But I doesn't seem to group as it's supposed to.

3 Comments

  1. After trying, I realized I wasn't using the Grouping property, the code will go like: 

    import org.joget.apps.form.model.*;
    import org.joget.apps.form.service.*;
    import java.sql.*;
    import org.apache.commons.collections.SequencedHashMap;
    import java.util.*;
    
    public FormRowSet getIslas() {
    	FormRowSet f = new FormRowSet();
            f.setMultiRow(true);
            Class.forName("org.postgresql.Driver").newInstance();
    	con = DriverManager.getConnection("jdbc:postgresql:/localhost:5432/database", "username", "password");
    	if(!con.isClosed()){
    		String sql = "SELECT keyname, value, grouping FROM tablename order by grouping, keyname"; // Here you can query from one or multiple tables using JOIN etc
    		PreparedStatement stmt = con.prepareStatement(sql);
    		ResultSet rs = stmt.executeQuery();
    		FormRow r1 = new FormRow();
                    r1.put(FormUtil.PROPERTY_VALUE, "");
    		r1.put(FormUtil.PROPERTY_LABEL, "-- Select --");
    		f.add(r1);
                    while (rs.next()) {
    			FormRow r2 = new FormRow();
    			r2.put(FormUtil.PROPERTY_VALUE, rs.getString(1));
    			r2.put(FormUtil.PROPERTY_LABEL, rs.getString(2));
                            r2.put(FormUtil.PROPERTY_GROUPING, rs.getString(3));
    			f.add(r2);
    	        }
    		rs.close();
    		stmt.close();
    		con.close();
    	}
    	return f;
    }
    
    return getIslas();
    1. Dear Victor,

      Don't forget close the connection before return f;

      rs.close();

      stmt.close();
      con.close();

      1. Hi Miklos,

        You are right, thanks.. I just added that code above