myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thai Dang Vu" <tdan...@momentumsystems.com>
Subject RE: How to Re-Initialize JSF Backing Bean on Form Submit
Date Thu, 14 Jun 2007 14:10:19 GMT
Have you ever tried Spring Web Flow? SWF supports conversational scope, flow scope ...., but
I think Seam is better because it has everything for a web app while if you go with Spring,
you need core spring, spring web flow and acegi (which is not very well-known for its integration
with jsf).

________________________________________
From: Iskandar Zaynutdinov [mailto:izaynutdinov@gmail.com] 
Sent: Thursday, June 14, 2007 12:18 AM
To: MyFaces Discussion
Subject: Re: How to Re-Initialize JSF Backing Bean on Form Submit


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



NOTICE: This message (including any attachments) from Momentum Systems, Inc. contains information
that is PRIVILEGED and CONFIDENTIAL.  If you are not an intended recipient, you are hereby
notified that any dissemination of this message is strictly prohibited.  If you have received
this message in error, please do not read, copy or forward this message.  Please permanently
delete all copies and any attachments and notify the sender immediately by reply email or
by calling our Office at 703.740.9300.

Mime
View raw message