0

Im currently testing on JSF Bean that make use of ViewScope

I notice this behaviour.

When having this button :

<p:commandButton value="Submit Data to Server" 
    ajax="false" update="debugPanel" />

I can see the postconstruct happens only once, and the submission triggered by this button doest trigger postconstruct, which is correct, since it's returning to the same view.

But when i add modify my button into this :

<p:commandButton value="Submit Data to Server" 
    ajax="false" update="debugPanel" 
    action="viewScope2.xhtml?faces-redirect=false"/>

I can see that the postconstruct method gets called for every submission, which means the bean doesnt retain it's state, although it's actualy returning to the same view. I thought this is because of the redirectin, so i omitted it, and the button becomes something like this :

<p:commandButton value="Submit Data to Server" 
    ajax="false" update="debugPanel" 
    action="viewScope2.xhtml"/>

But still, the postconstruct method gets called for every submission, which is not desireable.

Is it possible to have this idealism :

No matter whether it's explicitly or implicily defined (via attribute or via return "myview.xhtml" in action method) , whether it's using redirect or not, the viewscoped bean will always retain it's state when returning to the same view.

Please share your opinions !

Thank you .....

Bertie
  • 17,277
  • 45
  • 129
  • 182
  • Did you implement http://stackoverflow.com/questions/5416070/jsf-2-and-post-redirect-get ? That can be the cause. – BalusC Mar 25 '11 at 10:34
  • @BalusC: No, i did not in this case. Since without explicitly stating the target view, it still works fine, which is the first case in the original post. – Bertie Mar 26 '11 at 02:20

1 Answers1

0

Basically all these questions have been answered in this entry .. Thank you !

Community
  • 1
  • 1
Bertie
  • 17,277
  • 45
  • 129
  • 182