I have a bean:
@ManagedBean(name = "bExam")
@SessionScoped
public class BExam implements Serializable
{
private List<Category> categories;
private List<Category> categoriesSelected;
public BExam() {
categories = CategoryDb.getAll(); // there is ok. Categories has filled right.
categoriesSelected = new ArrayList<>();
getters & setters...
}
There is converter:
@FacesConverter("categoryConverter")
public class CategoryConverter implements Converter<Category> {
@Override
public Category getAsObject(FacesContext fc, UIComponent uic, String string) {
...
}
@Override
public String getAsString(FacesContext fc, UIComponent uic, Category t) {
return String.valueOf(t.getId());
}
}
There is selectManyCheckbox:
<h:selectManyCheckbox id="categories" value="#{bExam.categoriesSelected}" converter="categoryConverter">
<f:selectItems
value="#{bExam.categories}"
var="category"
itemLabel="#{category.name}"
itemValue="#{category}"/>
</h:selectManyCheckbox>
And this is Category model:
public class Category implements Serializable
{
private int id;
private String name;
private int sortOrder;
private int categorySetId;
getters & setters...
}
Checkboxes are builds right. When i click on any of them, in getAsObject
in string
parameter i always get "on"
.
What's happening there? Why this string comes exactly? And how solve it?