Form Grid

为文本框绑定内容

import org.joget.apps.form.model.*;

FormRowSet f = new FormRowSet();
FormRow r1 = new FormRow();
r1.put("description", "hello world");
f.add(r1);

return f;
Form Grid 存储/加载

import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import org.apache.commons.collections.SequencedHashMap;
import java.util.*;

public FormRowSet test() {
	FormRowSet f = new FormRowSet();
        f.setMultiRow(true);
        Class.forName("com.mysql.jdbc.Driver").newInstance();
	con = DriverManager.getConnection("jdbc:mysql://localhost:3307/jwdb?characterEncoding=UTF-8", "database username", "database password");

	if(!con.isClosed()){
		String recordId = "#requestParam.id#"; // Get the url parameter
		String sql = "SELECT * FROM test_table WHERE id=?"; // Here you can query from one or multiple tables using JOIN etc
		PreparedStatement stmt = con.prepareStatement(sql);
		stmt.setString(1, recordId);
		ResultSet rs = stmt.executeQuery();
		while (rs.next()) {
		FormRow r1 = new FormRow();
			r1.put("gridColumn1", rs.getString(1));
			r1.put("gridColumn1", rs.getString(2));
			r1.put("gridColumn1", rs.getString(3));
			f.add(r1);
	   }
	}
	return f;
}
return test();

Form Grid存储

import org.joget.apps.form.model.*;
import org.joget.apps.form.lib.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import org.apache.commons.collections.SequencedHashMap;
import java.util.*;
import org.joget.commons.util.UuidGenerator;

public FormRowSet getGridRows() {
	return rows ; // this will return the grid rows
}

public saveGridRows(FormRowSet rows) {
	Class.forName("com.mysql.jdbc.Driver").newInstance();
	con = DriverManager.getConnection("jdbc:mysql://localhost:3307/jwdb?characterEncoding=UTF-8", "database username", "database password");
	if(!con.isClosed()){

		String recordId = "#requestParam.id#";

		// If you need to query data from different table(s) and process it before saving it to database,
		// you can do it here


		UuidGenerator uuid = UuidGenerator.getInstance();

		Iterator i= rows.iterator(); // Iterating grid rows
		while (i.hasNext()) {
			FormRow row = (FormRow) i.next();
			String gridColumn1 = row.get("gridColumn1"); // reading grid column value
			String gridColumn2 = row.get("gridColumn2");
			String gridColumn3 = row.get("gridColumn3");
			String pId = uuid.getUuid(); // generating Primary Key
			String insertSql = "INSERT INTO table(id,col1,col2,col3) VALUES(?,?,?,?)";
			PreparedStatement stmtInsert = con.prepareStatement(insertSql);
			stmtInsert.setString(1, pId);
			stmtInsert.setString(2, gridColumn1);
			stmtInsert.setString(3, gridColumn2);
			stmtInsert.setString(4, gridColumn3);
			stmtInsert.executeUpdate();
		}
	} else {
		System.out.println("Connection Problem");
	}
	con.close();
}

FormRowSet rows = getGridRows(); // getting the grid rows
saveGridRows(rows); // processing & storing the grid rows

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值