1
0
-1

I've written a load binder using bean shell. In this code, I'm fetching values from local DB and inserting into form fields.

import org.joget.apps.app.service.*;
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import java.util.*;
import org.apache.commons.collections.SequencedHashMap;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;

public FormRowSet getData() {
 
    FormRowSet results = null;
 
    if (results == null) {
        results = new FormRowSet();
        results.setMultiRow(true);
        Connection con = null;
        try {
            //wait okay 
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/joget", "root", "root");
 
            if(!con.isClosed()){
                String sql = "SELECT id, address, state, pin, cmanager, DATE_FORMAT(date, '%M %d, %Y') FROM address NATURAL JOIN cmanager WHERE Id = #form.bd1.value#;";
                PreparedStatement stmt = con.prepareStatement(sql);
                ResultSet rs = stmt.executeQuery();
                while (rs.next()) {FormRow row = new FormRow();
                    row.put("id",      (rs.getString(1) != null)?rs.getString(1):"");
                    row.put("address", (rs.getString(2) != null)?rs.getString(2):"");
                    row.put("state",   (rs.getString(3) != null)?rs.getString(3):"");
                    row.put("pincode", (rs.getString(4) != null)?rs.getString(4):"");
                    row.put("manager", (rs.getString(5) != null)?rs.getString(5):"");
                    row.put("date",    (rs.getString(6) != null)?rs.getString(6):"");
                    results.add(row);
                }
            }
        } catch(Exception ex) {
            System.err.println("------------------>Beanshell Error" + ex.getMessage());
        } finally {
            try {
                if(con != null)
                    con.close();
            } catch(SQLException e) {}
        }
    }
   
    return results;
}
 
return getData();
 
}
 
return test();

As this code is getting inserted into form fields.


But I also want to insert the same values into custom HTML. Is it possible to insert the values into custom HTML using bean shell? Suggest me what changes do I need to make in the code to insert the values into HTML tags ?

 

Thankyou !!!

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      The custom html form element accepts hash variables from current form only if the current form fields have values in them upon form load. Else you may have to define a record ID in the Form Data Hash Variable.


      Also, seems from your load binder bean shell script, you could just use the JDBC Form Binder to write SQL query.

      1. Deepak Mishra

        I've been loading the form fields from the load binder. Is it possible to use those field values in the same form in the custom HTML field? 


        And how can I use load binder to directly inject those values in custom HTML instead of form fields?

      CommentAdd your comment...