-
1. Re: How to send a parameter with checkbox in JSF in order to
yj4jboss Dec 11, 2006 12:12 PM (in response to lara)I guess you want to implement multiple selections in a datatable. I experienced this issue a while ago and could only work around this problem with the following approach. Its requires a bit of work but it works fine ....
The idea is to have an object as a view with the boolean variable representing the selection status....
As such i have a Generic Viewpublic abstract class GenericView<T> { private boolean selected=new Boolean(false); private T persistentInstance; public boolean isSelected() { return selected; } public void setSelected(boolean isSelected) { this.selected = isSelected; } public T getPersistentInstance() { return persistentInstance; } public void setPersistentInstance(T persitentInstance) { this.persistentInstance = persitentInstance; } }
I then create a view specific for the object i want to usepublic class UserSelectionView extends GenericView<User> { }
And a Mapper class which will map the view to the object and vice versa as required :public abstract class UserViewMapper { public static User MapViewToUser(UserSelectionView view){ return view.getPersistentInstance(); } public static UserSelectionView MapUserToView(User user){ UserSelectionView view = new UserSelectionView(); view.setPersistentInstance(user); view.setSelected(false); return view; } }
In my SFSB, i then use the view as data model and a list of the object@DataModel private List<UserSelectionView> userViewListing = new LinkedList<UserSelectionView>(); @Factory("userViewListing") public void ListUserSelectionViews(){ List<User> userList = userDAO.selectAll(); for(User user:userList){ userViewListing.add(UserViewMapper.MapUserToView(user)); } } public void deleteSelectedUser(){ for(UserSelectionView userView:userViewListing){ if(userView.isSelected()){ userDAO.remove(UserViewMapper.MapViewToUser(userView)); } } }
Let me know how it goes ...
Cheers,
Jankee Yogesh
Software Developer
http://www.m-itc.net/ -
2. Re: How to send a parameter with checkbox in JSF in order to
lara Dec 12, 2006 7:25 AM (in response to lara)Thank you very much for replying!
I am trying your approach but I am having problems and nothing is listed in the page, seems the list is always empty. Can you please show me your JSF page? Should I keep the <h:selectBooleanCheckbox> and let its value call the setSelected method in the Generic view class?
I will be very thankful if you can explain more what you suggested because I am reallly stuck.
Regards