users@glassfish.java.net

Change a session managed bean

From: <glassfish_at_javadesktop.org>
Date: Tue, 19 Jan 2010 23:55:36 PST

Hello,
I have a managed bean ( an Entity ) that should be active during various requests. This can be solved by declaring the managed bean as session scoped with the annotation @SessionScope.
It is to say, I have a CRUD application that should maintain a managed bean during various pages. The problem is that the user can create a new object and this managed bean should change to an "empty" object (new MyObject()).
I tried to solve the problem by declaring the managed bean as a managed property of another managed bean. Then I tried to change the managed property with the setter function ( setMyObject(new MyObject() ). But, this does not work because the managed bean/property references the same object (just as if the function was not called).

I did another attempt by declaring the managed bean as request scoped (the default scope). Then I tried to maintain the reference to the object by declaring a GET parameter with the entity identifier as its value.But, this only works in the first request that makes the reference to point properly to the identifier. Next requests reset that value to a new object ( new Integer() ), and it seems that the reference to that identifier is no longer updated (I do not know why).
The code I use in the JSF page to update this identifier is:

<f:metadata>
            <f:viewParam name="product_id" value="#{price_controller.productId}" required="true" requiredMessage="No id specified.">
            </f:viewParam>
</f:metadata>

How is it possible to maintain a managed bean during various requests?

Thanks,
Pau
[Message sent by forum member 'pauca' (pau.carre_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=381893