Two Laptop Bag
The moose likes JSF and the fly likes JSF Tables with checkboxes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "JSF Tables with checkboxes" Watch "JSF Tables with checkboxes" New topic
Author

JSF Tables with checkboxes

Patrick Fong
Greenhorn

Joined: Feb 16, 2009
Posts: 5
Hi

I was wondering if someone could give me some pointers on constructing and processing checkboxes in a database table. I'm using JSF 1.2 and Tomahawk. Here is my JavaBean -


Here is my backing bean



What I need to do is list down all possible PLANNING, DOING and DONE activities. Then I want to select the checkboxes of the assigned activities of the fore-mentioned types. Then I want to be able to process the assigned and un-assigned activities.

This is where I'm not sure as I'm a JSF newbie. This is my attempt at writing the JSF page. Needless to say, it doesn't quite work the way it should. (This is only for PLANNING activities). Should there be a binding




My questions are
  • How do you write the JSF page to list activities of each type with checkboxes? How do I include assigned activities?
  • How do you process the check boxes or reference the checkboxes that are checked?
  • What should be in the constructor for AssociatedAttributeBean?


  • Cheers
    Patrick
    Bauke Scholtz
    Ranch Hand

    Joined: Oct 08, 2006
    Posts: 2458
    Inside an UIData component you should bind every component value to a property of the iterated row object, not to the parent backing bean. Otherwise the property of the parent backing bean will simply be overwritten everytime from up to the value of the last row. In this case you need to move the 'possiblePlanningActivities' property to the 'Activity' class and bind the value of the checkbox with #{currentRow.possiblePlanningActivities} instead.

    Another alternative is to bind it to a Map<TypeOfUniqueRowIdentifier, Boolean> property of the backing bean, where in TypeOfUniqueRowIdentifier should hold the value which represents the unique ID of the object behind "currentRow", the 'Activity' class. In this case I assume that the 'name' property is unique, so make 'possiblePlanningActivities' a Map<String, Boolean> property in the backing bean and bind the value of the checkbox with #{AssociatedAttributeBean.possiblePlanningActivities[currentRow.name]}. On checked rows, the Boolean property will evaluate to true.


    Code depot of a Java EE / JSF developer | JSF / Eclipse / Tomcat kickoff tutorial | DAO kickoff tutorial | I ♥ Unicode
     
    I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
     
    subject: JSF Tables with checkboxes
     
    Similar Threads
    dataTable troubles
    Simple list table
    datatable - row colors
    Action Event
    Which Package to Import to Use FacesContext's getRequestMap()?