0

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 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;
    }

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.

Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168
  • I'm having a hard time in understanding how this is a JSF problem. In its current form, this is logically just a matter of an `if` statement like so `if (accessAlreadyGranted(workclass, reportname)) { reports.add(reportname); }` What exactly is your problem with that? – BalusC Nov 18 '15 at 12:02
  • The checkboxes are already there say I am checking and saving the values in a database. On inquiry, Whatever I checked initially should be checked. – Stanley Mungai Nov 18 '15 at 12:27
  • Juse preset `reports` property with desired values as said before? – BalusC Nov 18 '15 at 12:50
  • I want to show both Checked and Unchecked Checkboxes. – Stanley Mungai Nov 18 '15 at 13:20
  • You already have `allreports` for that? Or is your concrete problem that you have in first place no idea how to use a `` in its simplest form? – BalusC Nov 18 '15 at 13:21
  • `allreports` gives me dynamic Checkboxes from the database. That is a `String[]` that gives me dynamic checkboxes. I am able to check them and submit the Information. What I am not able to do it have What I have already Submitted checked on the next Page Load – Stanley Mungai Nov 19 '15 at 13:53
  • Just preset `reports` property? That represents the checked values. – BalusC Nov 19 '15 at 13:59

0 Answers0