Hi All,
I am trying to get selected check box's value(multiple)
JSF View.............
<h:dataTable value="#{forward}" var="phone">
<h:column>
<h:selectBooleanCheckbox value="#{deleteSelections[phone]}" />
</h:column>
Maping in Action.........
@Out(scope=ScopeType.CONVERSATION, required=false)
Map<Forward, Boolean> deleteSelections;
deleteSelections = new HashMap<Forward , Boolean>();
And when i am trying to retrieve the value its getting Null for selected checkBox's....
for (Forward phoneAddress : forward)
{
System.out.println(deleteSelections.get(phoneAddress));
}
Any Idea what's wrong with my code?
Not sure you can bind to a map like that
I usually add a boolean attribute to the object in the datatable and hook the selectbox there. Then on the action, I iterate through the list to see which are selected and affected by the action.
If a man speaks in the forest and there is no woman around to hear him, is he still wrong?
Thanks for your reply.
I would like to try the way you have mentioned. Can you please magnify your thoughts(with any Example).
Some older thread
If a man speaks in the forest and there is no woman around to hear him, is he still wrong?
Thanks again, I am trying that solution but getting stuck for "list" in below mentioned reference code...
There are probably better/cleaner ways to do it but I have used a sort of
public class SelectedEntity {
private boolean selected = false;
private Entity entity;
public SelectedEntity(Entity entity) {
this.entity = entity;
}
... setters / getters
}
and then I return a List<SelectedEntity> to the datatable and bind the checkbox to var.selected and data to var.entity.entityproperty.
then when I perform an action I loop
for (SelectedEntity selectedEntity : list) {
if (selectedEntity.isSelected) {
doSomethingWith(selectedEntity.entity);
}
}
from where i will get that selected checkbox's list
I var referring to the list (whatever named) that backs the datatable. If you bind the table to
#{backingbean.theList}and there have a
then the iteration in the action would be
for (SelectedEntity selectedEntity : theList) {If a man speaks in the forest and there is no woman around to hear him, is he still wrong?
Hi Nicklas,
Thanks for your response :)
Remember, in mine 1st post i had asked for null value problem, i was getting that for multiple selection, that has resolved i had problem f: subview my logic was coming in between that block.
We actually don't need to hook another Boolean field for that.
And one more thing, do you know what actually that f: subview does, because of what i was getting Null values.