Reputation: 7256
I have a List of items that I would like to print on the webpage. For each item in the list I want to display a checkbox. When clicked on the checkbox the status of the item should be toggled.
TodoItem
has a property Status
that I want to update.
Status
public enum Status {
Active,
Completed,
Archived
}
Jsf Page
<ui:repeat value="#{todoBean.selectedList.todoItems}" var="todoItem">
<h:form id="todoItemStatus">
<h:selectBooleanCheckbox class="filled-in" id="todo-item" value="#{todoItem.status}">
<f:ajax listener="#{todoBean.toogleTodoItemStatus(todoItem)}" />
</h:selectBooleanCheckbox>
<h:outputLabel for="todo-item" value="#{todoItem.title}" />
</h:form>
</ui:repeat>
I have read that I cannot use converter
in the selectBooleanCheckbox
. When the checkbox is clicked, I want to update the TodoItem.status
to either completed
or active
.
How can I achieve this without adding another list in the backing bean?
Upvotes: 0
Views: 938
Reputation: 12337
Why not add two additional methods:
public Boolean getBooleanStatus() {
return status == Status.ACTIVE ? true : false; // But then what you really want
}
public void setBooleanStatus(Boolean boolStatus) {
this.status = boolStatus == true ? Status.ACTIVE : Status.COMPLETED; // But then what you really want
}
And in the xhtml:
<h:selectBooleanCheckbox class="filled-in" id="todo-item" value="#{todoItem.boolenStatus}">
But I do notice you have a 'tri-state' Status. Does that not cause a problem?
Upvotes: 1