This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JSF and the fly likes Datatable Refresh Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Datatable Refresh Issue" Watch "Datatable Refresh Issue" New topic

Datatable Refresh Issue

Hari Gundappa

Joined: Sep 13, 2011
Posts: 27

I have a screen with a datatable that has binding to a controller.

When user clicks on some radio buttons on the ui and saves, the a valuechange listener on the radio ,get the changed objects in the controller and updates
to the DB.

It is after this I have an issue to refresh the db with changed list. The list of objects i the datatable is retained as is, even though I refreshed 2 objects from DB with changed status.

Can some one help me with, how to refresh the changed list of objects to the datatable on the screen?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17150

JSF backing beans are not Controllers. They are Models.

You should not use valueChangeListeners to capture data. If the submitted form has validated data, JSF will automatically update the backing bean (Model) properties without any need for you to code for it. You can then use the action method to talk to the database.

When you submit a form using JSF, and your action method does not direct JSF to navigate to a new page, the same page will be redrawn using the updated Model values. If you are instead using AJAX to do a partial-page submit, you must tell the AJAX mechanism what parts of the page to refresh.

Binding is something that should not be used casually, despite what a lot of old out-of-date documentation might make you believe. The primary use for binding is cases where the model is actively modifying View UI, and that's not something that should be done too freely.

An IDE is no substitute for an Intelligent Developer.
Hari Gundappa

Joined: Sep 13, 2011
Posts: 27
Thanks Tim.

My problem is exactly as describe in you statement
the model is actively modifying View UI,

I have a requirement exactly as that and I want the UI datatable to be refreshed with the changed information after I process it.

I am using a value change listener only to capture the changed records on the UI.
So , say I have a screen with a datatable displaying user information , and there is radio button group to update his status ( viz Active/Inactive/NA) .

1)When for a user, one of those radio buttons is selected (this could done multiple users on the screen) and the a button called Update Changes is clicked,
2) I am capturing the changed rows of the datatable using getRowData()( this datatable is bound to the one on UI) in valuechange listener method of the radio button,
3)process those two and render the page back.

I do not knw if there is a btter way for 1 and 2.
However my problem is after 3. When the page is render the processed items have few field values that were upated fro teh DB(status etc) and I need the datatable to reflect it. By doing nothing after 3 , the screen is not refreshing the new info.

Hence I need some inputs to adress this.

Please Advise.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17150

I'm afraid you misinterpreted that. When I said "modifying the UI" I meant wholesale changes where you actually add or remove entire controls from the web page. Updating the contents of a UI control is not sufficient reason for using binding. Changing the control layout on a GUI can confuse the user, so it's not recommended in most cases, so therefore neither is binding.

The UI (View) is updated by the Controller (FacesServlet) when the Model (backing bean) has been changed and an HTTP submit request is made from the client to the server. Sub-Views (such as dataTables) are updated from their corresponding Sub-Models (TableModels). As long as the model mapping was configured properly in the View Definition, no programmer-supplied code is required.
I agree. Here's the link:
subject: Datatable Refresh Issue
jQuery in Action, 3rd edition