jQuery in Action, 3rd edition
The moose likes JSF and the fly likes To update a dataTable from backing bean using p:commandbutton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "To update a dataTable from backing bean using p:commandbutton" Watch "To update a dataTable from backing bean using p:commandbutton" New topic

To update a dataTable from backing bean using p:commandbutton

N Deepu

Joined: Jul 28, 2011
Posts: 28

Hi all,

How can I update a datatable from the backing bean? I'm using JSF 2.0 and Primefaces 2.2.1.
I'm doing this by JSF custom component. So I've to bind the datatable from the encode method. And in run time I should update the table after entering few details in the other fields.
I tried populating through p:commandbutton(setUpdate) from back end. But it says I can't create a p:commandbutton without a form though I've a form in my xhtml page.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

JSF is a framework built on the Model/View/Controller paradigm. In JSF, the View is the webpage, the Model is the backing bean and the Controllers are the FacesServlet and tag processors.

Controllers are the glue. When the Model changes, the Controller updates the View. When the View is changed (form controls input and submitted), the Controller updates the Model.

JSF does more than just this - it also invokes the business logic (action processors) and does validations, conversions, and so forth, but the heart of it all is MVC. For flexibility's sake, the rendering code in the Controller is segregated from the rest of the Controller, so that alternative rendering systems can be plugged in with minimal impact on the rest of the application.

A dataTable is both the View side (tag) and the Model side (tableModel), so when you say "update a dataTable", it's not clear which side you're talking about.

Using the stock components, if you click a commandButton on a form containing a dataTable, any input controls on that form (including ones in the dataTable) will be validated, and if found valid, changed values will be posted to the backing bean (Model). In the case of items in a DataTable, that means that the corresponding cells in its DataModel will be updated. Once the Model has been updated, the action processor will be invoked. It can do whatever it wants, including updating the Model objects. On completion of the action method, JSF's rendering phase kicks in and it will construct a new View. If that View contains references to updated Model values, the newly-rendered View will reflect these changes.

Of course, if you're coding a custom JSF tag at the binary level, you should already know that intimately. Otherwise, you're basically Walking Dead, since that's only the beginning of what you need to know. Creating new tags at the binary level is something that I actively discourage. They're going to be horribly expensive to create, debug, and maintain, and considering what a mess that whole part of the system is right now, I think there's a very good chance that JSF3 will replace the current internal architecture with something completely different, which means that any such code will probably break and break hard.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link: http://aspose.com/file-tools
subject: To update a dataTable from backing bean using p:commandbutton
It's not a secret anymore!