wood burning stoves*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to get checkbox value from datagrid." Watch "How to get checkbox value from datagrid." New topic
Author

How to get checkbox value from datagrid.

Dan Ji
Greenhorn

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: 15661
    
  15

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.

Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get checkbox value from datagrid.
 
Similar Threads
RichFaces with TabPanel and selectOneMenu not change the tab
two rich:datascroller in one page, one works, the other doesn't
Help with rich:datascroller
Skinning issue in Richfaces 4 and JSF 2
Edit or delete records resulting from search