How to populate File Upload Element using Bean Shell Load Binder
I am trying to populate a form with values stored in database using Bean Shell Load Binder, the result was shown below:
Most of the fields work fine with string, but for the File Upload element, it has some errors. When I click the hyperlink of the file, it shows the error below:
I am pretty sure this problem is happening because the way I populated the File Upload element. As only the name of the uploaded files are stored when the form is submitted, I am sure that it required some ways to link to the file path, but I am not sure how to do that. The codes I am using was shown below:
public FormRowSet load(Element element, String processId, FormData formData) {
FormRowSet rows = new FormRowSet();
if (processId != null && !processId.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 * FROM app_fd_capa_Main_History WHERE dateCreated=(SELECT MAX(dateCreated) from app_fd_capa_Main_History) AND c_caKey=?");
stmt.setString(1, processId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
FormRow row = new FormRow();
row.setProperty("personInChargeCA", (rs.getObject("c_personInChargeCA") != null)?rs.getObject("c_personInChargeCA").toString():"");
row.setProperty("departmentCA", (rs.getObject("c_departmentCA") != null)?rs.getObject("c_departmentCA").toString():"");
row.setProperty("dateCA", (rs.getObject("c_dateCA") != null)?rs.getObject("c_dateCA").toString():"");
row.setProperty("correctiveAction", (rs.getObject("c_correctiveAction") != null)?rs.getObject("c_correctiveAction").toString():"");
row.setProperty("evidenceCA", (rs.getObject("c_evidenceCA") != null)?rs.getObject("c_evidenceCA").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);
Does anyone know how to set the row property of File Upload element to be populated with the files stored in database? And how to make it auto download when we click on the file?

