Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get checkbox value from datagrid.

 
Dan Ji
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18025
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic