3

This question probably does not fit SO rules, but I'll ask it anyway. Answers might help other people struggling with JSF.


We are using JSF (MyFaces, PrettyFaces, PrimeFaces and Spring) on one of our biggest project for two years now (migrated from Tapestry 3). I can say that we are "recovering" from this migration to this day.

In my opinion one of our major mistakes was misunderstanding of JSF's VIEW SCOPE. JSF offers two basic mechanisms how you can persist VIEW STATE - CLIENT and SERVER. We went for the SERVER method, which was our first mistake as ViewExpiredException never stopped coming from that moment on. The next mistake was to store data on VIEW SCOPE as that prevented us from easily switching to CLIENT state saving method.

So I was thinking whether there are some best practices and guidelines on what should and shouldn't be stored on VIEW SCOPE (and thus serialized into VIEW STATE). Official documentation and specification does not provide that. But I came to a quite nice conclusion:

  • You should only store on VIEW SCOPE such information that you would normally (without JSF) pass as request parameters.

When you have a basic CRUD application without JSF, you would do this:

  • state of the form is preserved between requests by form values in POST parameters
  • state of the list (filtering, sorting, paging) is preserved between requests by query parameters

Is my conclusion correct? Do you have any other guidelines on what to store and what to never store inside VIEW SCOPE? Do any component frameworks have such guidelines?

Pavel Horal
  • 17,782
  • 3
  • 65
  • 89
  • 2
    Refer to http://stackoverflow.com/q/7031885/1065197 – Luiggi Mendoza Nov 05 '13 at 15:14
  • I understand different scopes and how they work. The question I am asking is more about *"What should be avoided when working with the VIEW SCOPE."* For example if you are making XLS import form, would you store 2MB XLS file inside VIEW SCOPE? Probably not... these kind of guidelines and best practices is what I seek. But I feel that the question is too vague and would be better suited for some forum discussion... – Pavel Horal Nov 07 '13 at 08:38
  • If you already understand how the view scope behaves, then you should have the answer already. And for your last case, any file uploaded must not remain in memory too often, so that won't be a managed bean scope problem but a variable scope problem, that should live only in the method where it is created and nowhere else. – Luiggi Mendoza Nov 07 '13 at 14:32

1 Answers1

-2

i use the following Guidelines:

  • avoid VIEW SCOPE as it is only available for Faces Manages Beans.
  • better: avoid the usage of Faces Managed Backing Beans. use CDI Managed Backing Beans to ensure portability. (sure, this is only possible if you have any cdi container available... in Java EE 6 and newer...)
  • avoid AJAX with JSF. (or only use it with caution for simple UIs...)
StefanHeimberg
  • 1,455
  • 13
  • 22