我有来自数据库的动态复选框,我需要根据布尔值 true 或 false 在页面加载时检查它们:
我的xhtml:
<h:selectManyCheckbox value="#{report.reports}">
<f:selectItems value="#{report.allreports}" />
</h:selectManyCheckbox>
我的布尔值:
public boolean checkedBox(String workclass, String reportname) {
Connection conn;
int count = 0;
try {
conn = db.getDbConnection();
String sql = "select count(*)NUM from rep_access where user_work_class = ? and rep_name = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, workclass);
ps.setString(2, reportname);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
count = rs.getInt(1);
}
DBConnection.closeConn(conn);
} catch (SQLException asd) {
System.out.println(asd.getMessage());
} catch (IOException asd) {
System.out.println(asd.getMessage());
}
return count > 0;
}
如果布尔值返回 true,我如何才能检查我的复选框。reportname
是复选框的值,workclass
值在会话中。