Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a table with a checkbox column dynamically in JSF

 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sirs and Madams,
I am very new to JSF and would appreciate any help on the current issue am having. I have data being displayed on a browser via a JSF table, and the table is bound to a userVOArray attribute on the managed bean. All works well and I have a able of users displayed (first name, last name, user type etc). As the array is populated by data pulled from a database, its size changes depending on users being added or deleted. I wish to add a column of checboxes to the table allowing me to delete a user whose corresponding checkbox has been checked. How would I go about this please?

Thanking you profusely in advance,
Nick
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18156
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF is based on the Model/View/Controller architecture. So the view (datatable) can only display what's in the model.

Your problem is that the original rows of the datatable don't possess a "delete me" attribute.

You get around this by building a model that does. In other works, instead of binding the datamodel directly to the view, construct a fa├žade class that includes the original attributes of a datamodel row plus a boolean item that indicates deletion and build your view model using instances of this class. You can then reference this view model when looking for items to delete.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find here two examples: http://balusc.blogspot.com/2006/06/using-datatables.html#SelectMultipleRows
 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanking you both for your prompt responses, I will try your suggestions and get back to you with any further queries.

Thanks again,
Nick
 
Phoenix Kilimba
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again, am pleased to say the suggestions made came in extremely useful and I have sorted out the dynamic checkbox issue, thanks again! However I now have a similar issue: I would like to have a new column next to the checkbox column, also dynamic with a button so that when that button is clicked on, that row is selected to be edited (However if there is a better way of fulfilling such a use case please let me know). Am using a Table as opposed to a datatable from the palette in netbeans, not sure if that makes a difference but thought I would add the info.

Thanking you profusely in advance for any input,
Nick
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make use of the rendered attribute.



Or something simliar that.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18156
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google for "JSF for Nonbelievers" by Rick Hightower - it's a 4-part series of articles in the IBM Developerworks collection. He presents an excellent illustration of this kind of thing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic