I have JSF lifecycle and design question. I am building a prototype, porting an existing Struts based application to JSF. The issue I am facing is I believe related to the JSF lifecycle, I need input from you folks as to whether what I am doing is the right way.

Here is the scenario of my application -

I have a page with a form with values populated from the database. The end user makes changes to the fields, and presses the commandbutton save. The values are saved to the database and the same page presented again with the new saved values.

Here is how I have implemented it -

The constructor of the backing bean makes the call to the model layer ( eventually EJB's), gets the initial data and displays it to the page. After user makes the changes, on pressing the commandbutton, the event handler, makes a call to the modellayer for saving the new data. After the save I populate the backing bean attributes with the new values, and display the same page again. All my backing beans are request scope ( and that's how I want them). I am using Myfaces implementation, and myfaces components.

Here is the problem I face -

The issue I am facing is that on calling save, or any other event, the constructor is called again . So eventually it ends up that there are double calls to the modellayer/database than what is required.

Is the way I am populating my backing beans wrong? Or is this the only way JSF handles things. Any input would be appreciated.

Reply via email to