File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes How to get checkbox value from datagrid. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to get checkbox value from datagrid." Watch "How to get checkbox value from datagrid." New topic

How to get checkbox value from datagrid.

Dan Ji

Joined: Aug 11, 2010
Posts: 1
Hi all, I am new to JSF and just started my first project. I have some questions about the datagrid and form submission.
I have a datagrid with a list checkbox in PageA, after I select some checkbox in the datagrid, i want the backend bean to retrieve the selected rows, then process these selected rows, finally display the result in PageB.

So I have PageA, submit the form with some selected rows in datagrid.
I have a PageB, PageB displays the processed result from the selected rows.

I have my PageA jsf page like this:

My first question:
1. For page navigation, in commandButton, should I use action="PageB", or use actionListener="#{MyBean.method}". I don't know how the backendbean get the selected rows and then process these rows, then navigate to PageB?

2. In backend MyBean, how can i retrieve the selected rows from the datagrid, could anyone give some examples?

Thank you very much for your help!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

1. You usually want an action processor. It works with the data that was just input and makes the decision on which new page to go to - or not. I recommend a simple action method for most purposes. Action Listeners are more complicated and less portable. They're primarily for cases such as when you need to fire off actions in more than one bean off a single button click. And even then, it may may more sense to inject the other bean(s) into a master-controller bean and let its action processor invoke their actions as POJO method calls.

2. adaptHitBean.adaptHits is required to be a JSF DataModel object. To be able to accept input, that basically means that its one of the collection datamodel types such as ListDataModel. When the action method is fired, you can obtain the wrapped List object from the ListDataModel using the getWrappedData() method and the updated values will have been placed in the rows of that list, including the state(s) of the check box(es). For a row-level action, such as a commandButton or commandLink in a datatable row, there's a pair of model methods, one of which will return the index of the row containing that button/link and the other of which can return the row object itself.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: How to get checkbox value from datagrid.
jQuery in Action, 3rd edition