user1285928
user1285928

Reputation: 1476

How to create a JSF table with checkboxes?

I want to create a JSF table like this. But instead delete button in every row I want to place check box in every row in the first column because I want to delete more than one row simultaneously. How I can create such a row and delete button which deletes every selected row? And can this be done with AJAX? I don't want to refresh the page.

Best wishes

Upvotes: 1

Views: 4038

Answers (2)

Daniel
Daniel

Reputation: 37061

Since you want an example that uses f:ajax and since other answer uses the given example in How to use JSF's h:selectBooleanCheckbox with h:dataTable to create one object per row? which is aimed for jsf 1 (and not 2) you can modify the delete button into something like this (make use of the f:ajax)

<h:commandButton value="Delete Selected">
    <f:ajax execute="@form" render="@form" listener="#{bean.submit}"/>
</h:commandButton>

and change public void submit() into public void submit(AjaxBehaviorEvent ev)

Upvotes: 4

Steven De Groote
Steven De Groote

Reputation: 2233

Balusc has a great tutorial about datatables in JSF. One part is about row selection with checkboxes: http://balusc.blogspot.com/2006/06/using-datatables.html#SelectMultipleRows

Upvotes: 3

Related Questions