Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
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
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;
import
org.joget.commons.util.LogUtil;
public
FormRowSet load(Element element, String username, FormData formData) {
FormRowSet rows =
new
FormRowSet();
if
(username !=
null
&& !username.isEmpty()) {
Connection con =
null
;
try
{
// retrieve connection from the default datasource
DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean(
"setupDataSource"
);
con = ds.getConnection();
// execute SQL query
if
(!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 =
new
FormRow();
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 used
try
{
if
(con !=
null
) {
con.close();
}
}
catch
(SQLException e) {
/* ignored */
}
}
}
return
rows;
}
//call load method with injected variable
return
load(element, primaryKey, formData);
thanks
fabian