Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
25. Jul 2008, 06:54 CET | Link

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?

6 Replies:
25. Jul 2008, 07:07 CET | Link

Not sure you can bind to a map like that

I usually add a selected 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?

25. Jul 2008, 07:11 CET | Link
Hi Nicklas,

Thanks for your reply.

I would like to try the way you have mentioned. Can you please magnify your thoughts(with any Example).

25. Jul 2008, 07:14 CET | Link
 

If a man speaks in the forest and there is no woman around to hear him, is he still wrong?

25. Jul 2008, 08:36 CET | Link
Hi Nicklas,

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

25. Jul 2008, 08:52 CET | Link

I var referring to the list (whatever named) that backs the datatable. If you bind the table to


#{backingbean.theList}

and there have a


  private List<SelectedEntity> theList = new ArrayList<SelectedEntity>() // (+setters/getters

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?

Rating:  * * * * *
26. Jul 2008, 18:10 CET | Link

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.