3

all

I novice in JSF2 (used Mojarra + primeFaces on tomcat7) and I get strange behavior of ManagedProperty object:

@ManagedBean
@ViewScoped
public class CreateFactMB implements Serializable{

    @ManagedProperty(value="#{collectionFactTable}") 
    private CollectionFactTable collectionFactTable; //SessionBean
    ...
    //setters/getters

I printed object when I open page (refresh brouser) I see one instance of collectionTree

mbeans.CollectionFactTable@12803ba

But when I do ajax request

<p:commandButton id="btn1" value="Save" update="growl"
                actionListener="#{createFactMB.doUpdate}" />    

In doUpdate I see another instance of my collectionTree

mbeans.CollectionFactTable@625c49

It's problem because I can not do change while ajax action (because I have just copy)

Anybody can help me? What I'M doing not right?

Akvel
  • 924
  • 1
  • 15
  • 32
  • 1
    the values printed seems to be for class **CollectionFactTable** and not **CollectionTree**, you made a typo or looking at wrong value !!! – baba.kabira Jul 19 '12 at 09:54
  • Ups .. it's my typo when copy - Here right - @ManagedProperty(value="#{collectionFactTable}") private CollectionFactTable collectionFactTable; – Akvel Jul 20 '12 at 02:50

1 Answers1

1

I think you have a misunderstanding of how SessionScoped persistence works in JSF. This behavior is expected and normal.

enter image description here

At the beginning of the request all of the managed beans are instantiated regardless of scope. In the Restore View phase, the session based persistence values are set to the new managed bean object, effectively restoring the SessionScoped bean back to its last state before the last Response was sent.

Once the Response is complete and has been sent the data in these managed bean instances is persisted and the objects dereferenced for garbage collection. The process begins anew at the next request, regardless if it is Ajax or not.

maple_shaft
  • 10,435
  • 6
  • 46
  • 74
  • I found soulutin http://stackoverflow.com/questions/6711321/session-bean-being-lost. Just need put javax.faces.STATE_SAVING_METHOD=server in web.xml – Akvel Jul 25 '12 at 05:29