0

I want to do some opertaions in the row of my JSF datatable, and for that i need and id of row. But when i see html generated through firebug. I notice that id is getting generated only for JSF components not of tr and td. Is there someway by which i can define the id of row(tr) Here is my code

<h:datatable value = "#{bean.list}" var = "row">
   <h:column> 
       #{row.name}
   </h:column>
   <h:column> 
       #{row.address}
   </h:column>
   <h:column> 
       #{row.phone no}
   </h:column>
   <h:column> 
       <h:selectBooleanCheckbox id="checkbox" value="#{row.sportsStudent}" />
   </h:column>
</h:datatable>

There is a button below my datatable which says "Show only sports student" and my list should show only sports student and caption will change to "Show all students" . now all students should be displayed. So i was thinking if i have id of tr . I can just hide/show that row using jquery. So can i do that ?

Thanks in advance.

Tarun Madaan

Tarun Madaan
  • 401
  • 1
  • 8
  • 20
  • In some blogs , i read about uidata and somewhere i read about selectabledatamodel. but i am newbie to JSF. can i go on with some simpler approach? – Tarun Madaan Apr 08 '12 at 15:01

1 Answers1

4

You have several options. I can propose 2 of them:

  1. You can add class with description to some column in datatable. E.g. for sports student class is sport and ordinary for others. And then you can hide/show all rows, which contains elements with ordinary class.
  2. Filter students on server. Send ajax request which will rerender your table, leaving only sports student. You can do this pretty simple if you use some JSF library with ajax support, e.g. primefaces.
Mikita Belahlazau
  • 15,326
  • 2
  • 38
  • 43
  • Thanks for your reply. But i can change the sports field of student and need to rerender the table when i click on button and i also need to see if the caption on button is "show sports students" or "show all". so how will i do that as per your fist solution ? can you please put more light on that... and as far as second solution is concerned , i am not supposed to use such libraries . need to do that only through JSF. – Tarun Madaan Apr 09 '12 at 04:21
  • You can hide all rows with ordinary students like this: `$('.ordinary').each(function(ind, el) { $(el).parent('tr').hide(); }));` And you can change text of the button using jquery. – Mikita Belahlazau Apr 09 '12 at 07:07
  • Look at [each](http://api.jquery.com/each/) function. We have an array of elements with class `ordinary` for every element from the array we call function passed to `each` method. – Mikita Belahlazau Apr 09 '12 at 08:59