myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Iskandar Zaynutdinov" <izaynutdi...@gmail.com>
Subject Re: How to Re-Initialize JSF Backing Bean on Form Submit
Date Thu, 14 Jun 2007 04:17:45 GMT
On 6/14/07, bansi <mail2bansi@yahoo.com> wrote:
>
>
> 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 <mail2bansi@yahoo.com> 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 <mail2bansi@yahoo.com> 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.
>
> Don't use session beans! Use request scoped beans

Mime
View raw message