Welcome to the JavaRanch, Hadu!
It's always a good idea when publishing sample code to reduce to the minimum amount of text you can rather than simply dumping the whole thing into the message.
You're dealing with people who don't get paid for their advice, and when your sample doesn't fit on the screen, a lot of people aren't going to spend the effort to bother reading through the whole thing.
I didn't, but I've seen problems like this enough that I'll give my standard answer and we'll see if it helps.
First, understand that unlike traditional GUIs, such as Swing, displaying a Dialog Box in
JSF doesn't cause any server interaction (unless you explicitly request it via AJAX). That is because the Dialog Box - and its field contents - are rendered when the page is initially displayed, but kept hidden. The "show()" dialog method therefore doesn't construct or populate the dialog, just makes what's already in the web page visible.
Typically, I'll have an "onshow()" method defined for the dialog that issues an AJAX request. This request will inform the server to locate a record to be edited (or construct a new, blank one), and populate its fields in the dialog controls (via AJAX partial page update).
This is done before the dialog actually becomes visible, so the dialog show in ready-to-edit form.
If the user later clicks the dialog's "Save" button, another AJAX request is made. This one submits the dialog's control values (the dialog is almost always defined in an h:form). The normal JSF lifecycle is run (data validation, valuechangelisteners fired as needed, backing bean values update) and the AJAX listener (action) method is then invoked. This action method can then post the user's input data out the the database.
In real life, this is a little more complex, since if the action fails for some reason (for example, adding a duplicate record), then feedback mechanisms are required to tell the client not to hide the form, but to display an error message and allow correction of form data. Or whatever failure actions you think appropriate.