What is the appropriate way to call selectAll Java method when from bean when I click on a checkbox?
<f:facet name="header">
<h:selectBooleanCheckbox binding="#{bean.selectAll}" onclick="highlight(this)" class="checkall"/>
</f:facet>
binding is not working. I just want to execute the code in this Java method.
EDIT
private HashMap<String, Boolean> selected = new HashMap<>();
public void selectAll() throws Exception {
String SqlStatement = null;
if (ds == null) {
throw new SQLException();
}
Connection conn = ds.getConnection();
if (conn == null) {
throw new SQLException();
}
SqlStatement = "SELECT ID FROM ACTIVESESSIONSLOG";
PreparedStatement ps = null;
ResultSet resultSet = null;
int count = 0;
try {
conn.setAutoCommit(false);
boolean committed = false;
try {
ps = conn.prepareStatement(SqlStatement);
resultSet = ps.executeQuery();
selected.clear();
while (resultSet.next()) {
selected.put(resultSet.getString("ID"), true);
}
/*
for (Map.Entry<String, Boolean> entry : selectedIds.entrySet()) {
entry.setValue(true);
}
*/ conn.commit();
committed = true;
} finally {
if (!committed) {
conn.rollback();
}
}
} finally {
ps.close();
conn.close();
}
}
Use
<f:ajax>to send an ajax request.with
Ideally the bean should be placed in the view scope by
@ViewScopedto keep it alive across the ajax requests on the same view.Don’t use
bindingto a bean property unless you have a very good reason. It’s intented to bind the wholeUIComponentto the bean which allows dynamic component manipulation, but more than often there are simpler and less obtrusive ways.