Hi ,

I have developped a JAVA code on bean shell form binder to display the list of username available in my jwdb database in a grid column . My code work well in Eclipse  :see below code

--

package JogetCode;
import java.util.*;
import java.sql.*;
public class JavaCodeForJoget {

    /**
     * @param args
     * @throws ClassNotFoundException
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/jwdb?characterEncoding=UTF-8", "root", "");
            if(!conn.isClosed()){

                String sql = "SELECT * FROM dir_user";
                PreparedStatement stmt = conn.prepareStatement(sql);
                ResultSet rs = stmt.executeQuery();
                while (rs.next())

Unknown macro: {                    System.out.println(rs.getString(1));               }

            }
        } catch (SQLException e)

Unknown macro: {            e.printStackTrace();        }

    }
}

---

I have adapted this code to my joget form :

See below for code :

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 test() {
    FormRowSet f = new FormRowSet();
        f.setMultiRow(true);
        Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://localhost:3307/jwdb?characterEncoding=UTF-8", "root", "");

    if(!con.isClosed()){
        String sql = "SELECT * FROM dir_user";
        PreparedStatement stmt = con.prepareStatement(sql);
        ResultSet rs = stmt.executeQuery();
        while (rs.next())

Unknown macro: {        FormRow r1 = new FormRow();            r1.put("gridColumn1", rs.getString(1));            f.add(r1);       }

    }
    return f;
}
return test();

--

my display is :

FormUtilprojectleader
gridColumn1

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

I dont see the username but only delete row button . The number of user in my db is 15 . I can see 15 lines in the grid but the nale is not being displayed.

Thank you all for your help .

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • No labels

6 Comments

  1. i wanted to say "the name is not being displayed " ^^

  2. How do you design your grid? Did you use the correct column ID?

    Try to read up Load & Store Form Grid Data Using Bean Shell Form Binder

    1. Hi walter , is this ok ? Or do i need to add options ?

  3. I have add two columns in options and i modify my code as : 

    r1.put("column1", rs.getString(1));

    r1.put("column2", rs.getString(2));


    i am getting this error : 

  4. The problem has been solved . I have adapted my code to a drop down list box (and not a grip) and all users are being showed correctly . regards , Meven . 

  5. Correct Grid design should look like this:

     

    beanshell script part:

    FormRowSet f = new FormRowSet();
    f.setMultiRow(true);
    FormRow r1 = new FormRow();
    r1.put("gridColumn1", your_value);
    r1.put("gridColumn2", your_value);
    r1.put("gridColumn3", your_value);
    f.add(r1);