mardi 17 novembre 2015

Load checked checkbox from database in JSF based on boolean

I am having dynamic Checkboxes from database and I need them to be checked on page load based on a boolean true or false:

My xhtml:

 <h:selectManyCheckbox value="#{report.reports}">
    <f:selectItems value="#{report.allreports}" />
 </h:selectManyCheckbox>

My Boolean:

 public boolean accessAlreadyGranted(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;
    }

How can I get My check boxes to be checked if the boolean return true. reportname is the value of the check box and workclass value is in the session.




Aucun commentaire:

Enregistrer un commentaire