加载多行表单数据

应用场景

  • 用于加载表单表格/高级表单表格/列表表格数据

样例代码

    1. 选择beanshell加载绑定器
    2. 替换样例代码中的
      • appId - 应用ID
        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.FormRow;
        import org.joget.apps.form.model.FormRowSet;
        
        	/**
        	 * 数据检索
        	 * @return
        	 */
        	private FormRowSet select() {
        		FormRowSet rows = new FormRowSet();
        		rows.setMultiRow(true);
        
        		Connection con = null;
        		PreparedStatement ps = null;
        		ResultSet rs = null;
        		try {
        			DataSource ds = (DataSource) AppUtil.getApplicationContext()
        					.getBean("setupDataSource");
        			con = ds.getConnection();
        			if (!con.isClosed()) {
        				String sql = "SELECT * FROM dir_user";
        				ps = con.prepareStatement(sql);
        				rs = ps.executeQuery();
        				while (rs.next()) {
        					FormRow row = new FormRow();
        					row.setProperty(
        							"username",// form grid 或 list grid 中列名
        							(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() : "");
        
        					rows.add(row);
        				}
        			}
        		} catch (Exception e) {
        			e.printStackTrace();
        		} finally {
        			try {
        				if (con != null) {
        					con.close();
        				}
        			} catch (SQLException e) {
        				// ignored
        			}
        		}
        		return rows;
        	}
        	/**
        	 * 主方法
        	 * @return
        	 */
        	public FormRowSet run(){
        		return select();
        	}
        	run();
        
        
Create by Sean Fung on 2016-06-01 16:54:05.0
Last updated by Sean Fung on 2016-06-01 16:54:05.0