i have requirement, in that i am showing a Datatable, above that table i have form in that i can register a employee, after clicking on submit employee data have to be saved in the database aswell as i have to update datable, so that i can see that registered employee in that Datatable,
how can i full fill this requirement
i am using jsf 2.0, ejb3.0,jpa 2.0.
in managed bean i am call this service as fallow in init method, and i am binding same this. employee list to UI
for every submit button click i have to query database or is there any mechanism to update List / can we use entity manager in anyway so that we can update Employee List
There are 2 types of Model object in your scenario.
One is the GUI Model. Anchored by one or more JSF Backing Beans.
The other is the ORM Data Model.
JSF works with POJOs, so ORM and GUI data models can be connected, although using an ORM model object as the anchor GUI model (backing bean) doesn't work too well, since JSF's bean manager doesn't have mechanisms to handle non-unique bean instances or persistent find/fetch/store.
The dataTable sub-View tag is backed by a DataModel sub-Model object. There is no actual requirement that the sub-model collection data be the actual ORM Model collection. You can create an intermediary collection to serve as a window into the ORM collection that more accurately reflects the contents and ordering of what you want the end user to see. Like so:
* The DataTable wrapper object for the GUI model list can be omitted, but JSF will construct an anonymous one if you do. It holds the cursor information needed to render data going out and determine the row selected coming back.
You can make this presentation List object anything you want. Subclass the original ORM objects and decorate them, which is how I get support for checkboxes on databases with no binary column types. Re-order the fields from the ORM List. Only include odd- or even-numbered ORM List objects. Whatever.
OR, include the newly-added record built in your JSF code into the presentation List and avoid re-fetching the ORM model object list. Nothing says that the presentation list need only contain objects in the ORM fetched modeel objects List.
Now practically speaking, I do re-fetch. But that's because it's simpler to do and because it allows me to pick up any possibly-pertinent changes made to the fetched object collection that may have come in from outside sources.
I feel no guilt about that because I keep my set of fetched data small and have confidence that the ORM layer can take advantage of caching mechanisms to reduce the actual overhead of a refresh-fetch. And because if performance issues do arise, it's easier to build a fine-tuned solution on a simple codebase than to take a pre-tuned solution that was tuned for the wrong things and change it.
And, just to round out the tale, for those who aren't well-practiced in JSF, I'll note that whatever is in your presentation list will automatically be what's displayed in the dataTable when the page is refreshed after the committing action method is invoked. JSF's built-in Controllers will ensure that as part of the core JSF functionality.
An IDE is no substitute for an Intelligent Developer.