Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 90202 invoked from network); 14 Jun 2007 04:01:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Jun 2007 04:01:22 -0000 Received: (qmail 51873 invoked by uid 500); 14 Jun 2007 04:01:20 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 51844 invoked by uid 500); 14 Jun 2007 04:01:19 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 51833 invoked by uid 99); 14 Jun 2007 04:01:19 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jun 2007 21:01:19 -0700 X-ASF-Spam-Status: No, hits=0.9 required=10.0 tests=FORGED_YAHOO_RCVD,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jun 2007 21:01:13 -0700 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1HygVw-00086R-Sw for users@myfaces.apache.org; Wed, 13 Jun 2007 21:00:52 -0700 Message-ID: <11113434.post@talk.nabble.com> Date: Wed, 13 Jun 2007 21:00:52 -0700 (PDT) From: bansi To: users@myfaces.apache.org Subject: Re: How to Re-Initialize JSF Backing Bean on Form Submit In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: mail2bansi@yahoo.com References: <11110517.post@talk.nabble.com> <11110875.post@talk.nabble.com> <11111042.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org Thanks Andrew. As very correctly suggested by you i already have the code in backing bean to clear the backing bean properties. But the problem is when i move back and forth (i.e. navigate) from Current page to Other pages and come back to Current page, i want the backing bean associated with the current page to be re-created i.e. new instance of backing bean. Ofcourse i wanna clear the data on form fields Andrew Robinson-5 wrote: > > I didn't mean to clear the form, but clear the backing bean properties. > > public class MyBean { > private MyObject myObject; > > public String save() { > // EntityManager or hibernate session save here > // clear the properties: > clearState(); > } > > public void onCancel(ActionEvent evt) { > clearState(); > } > > private void clearState() { > myObject = null; > } > } > > On 6/13/07, bansi wrote: >> >> I figured out that i can do something like this ... >> In session scope, only one instance of the backing bean will be used >> during >> the whole browser session. When you want to recreate the managed bean >> inside >> the backing bean during session, then do >> FacesContext >> .getCurrentInstance() >> .getExternalContext() >> .getSessionMap() >> .put("myBean", new MyBean()); >> >> BUT i am not sure where to put this snippet of code. >> >> >> >> bansi wrote: >> > >> > Andrew >> > I totally agree with you on "its the desired behavior of a session bean >> -- >> > one instance for the >> > user's session" >> > But is their a way to recreate the instance of backing bean in >> following >> > situations >> > 1) Whenever a new record is inserted into database. The reason i >> mention >> > this is my backing bean instantiates the pojo and for subsequent save >> into >> > database the backing bean holds onto the old instance of pojo having >> same >> > identifier (ID) value. This is exactly the reason Hibernate throws >> > Detached Object Exception passed to Persist >> > >> > 2) Whenever i navigate between JSF pages , i wanna backing bean to be >> > re-initialized i.e. re-created with new instance >> > >> > Please note as suggested by you i am not looking to clear off the >> fields >> > on the form whereas i want to recreate the whole backing bean itself >> > >> > Any pointers/suggestions highly appreciated >> > >> > Regards >> > Bansi >> > >> > >> > Andrew Robinson-5 wrote: >> >> >> >> That is the desired behavior of a session bean -- one instance for the >> >> user's session. If you want to use session, and have it be able to be >> >> cleared, then you will want to create a clear action or action >> >> listener method that clears all of the member variables when executed. >> >> >> >> I would instead recommend using conversational scope from JBoss-Seam >> >> or MyFaces or request scope and use saveState as needed to persist >> >> values across pages. >> >> >> >> -Andrew >> >> >> >> On 6/13/07, bansi wrote: >> >>> >> >>> We have backing bean defined in "session" scope >> >>> So whenever we do a submit on JSF Form, it holds onto same backing >> bean. >> >>> This is not desirable as >> >>> -> The Form will have different set of values each time it does a >> >>> submit >> >>> -> The Backing bean has variable defined to instantiate a POJO >> >>> i.e.private >> >>> MyPojo pojo = new MyPojo(); >> >>> So every time JSF form submits to the backing bean, it holds onto the >> >>> same >> >>> instance of POJO which eventually results in insertion problems into >> >>> database i.e. having same Identifier (ID) value >> >>> -> The same problem occurs if i navigate to different page and come >> back >> >>> to >> >>> original page >> >>> >> >>> Is their a way to re-initialize the Backing Bean ??? >> >>> -- >> >>> View this message in context: >> >>> >> http://www.nabble.com/How-to-Re-Initialize-JSF-Backing-Bean-on-Form-Submit-tf3918359.html#a11110517 >> >>> Sent from the MyFaces - Users mailing list archive at Nabble.com. >> >>> >> >>> >> >> >> >> >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/How-to-Re-Initialize-JSF-Backing-Bean-on-Form-Submit-tf3918359.html#a11111042 >> Sent from the MyFaces - Users mailing list archive at Nabble.com. >> >> > > -- View this message in context: http://www.nabble.com/How-to-Re-Initialize-JSF-Backing-Bean-on-Form-Submit-tf3918359.html#a11113434 Sent from the MyFaces - Users mailing list archive at Nabble.com.