1
0
-1
1 answer
- 10-1
Hi, did you have a look at Load & Store Form Grid Data Using Bean Shell Form Binder? There are examples to load and store form grid data using bean shell.
Add your comment...
Hi, did you have a look at Load & Store Form Grid Data Using Bean Shell Form Binder? There are examples to load and store form grid data using bean shell.
Hi Experts,
I have a form and have a Grid on it, i need load fields from same table that is used by the form , i did try using form hash variable but this option don´t get info.
Note: If i use a text box i can get the value of field without problems¡
This is the Table structure of the table:
In other hand i know that i can use bean shell to load data but need help to understand better the code, i´m using the example bellow:
Facts:
The table have an id field named id as we can show in the example
importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjavax.sql.DataSource;importorg.joget.apps.app.service.AppUtil;importorg.joget.apps.form.model.Element;importorg.joget.apps.form.model.FormData;importorg.joget.apps.form.model.FormRow;importorg.joget.apps.form.model.FormRowSet;importorg.joget.commons.util.LogUtil;publicFormRowSet load(Element element, String username, FormData formData) {FormRowSet rows =newFormRowSet();if(username !=null&& !username.isEmpty()) {Connection con =null;try{// retrieve connection from the default datasourceDataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");con = ds.getConnection();// execute SQL queryif(!con.isClosed()) {PreparedStatement stmt = con.prepareStatement("SELECT username, firstName, lastName, email from dir_user where username=?");stmt.setObject(1, username);ResultSet rs = stmt.executeQuery();while(rs.next()) {FormRow row =newFormRow();System.out.println(rs.getObject("username") );row.setProperty("username", (rs.getObject("username") !=null)?rs.getObject("username").toString():"");row.setProperty("firstName", (rs.getObject("firstName") !=null)?rs.getObject("firstName").toString():"");row.setProperty("lastName", (rs.getObject("lastName") !=null)?rs.getObject("lastName").toString():"");row.setProperty("email", (rs.getObject("email") !=null)?rs.getObject("email").toString():"");rows.add(row);break;}}}catch(Exception e) {LogUtil.error("Sample app - Form 1", e,"Error loading user data in load binder");}finally{//always close the connection after usedtry{if(con !=null) {con.close();}}catch(SQLException e) {/* ignored */}}}returnrows;}//call load method with injected variablereturnload(element, primaryKey, formData);thanks
fabian