1
votes

I know that there are many different architectures exist. In this question I consider 3-tiers architecture (presentation-services (busyness logic)-data access layer (DAOs). And I want to concentrate on how presentation tier works with services tier.

The problem I met is standard. I have stateless services layer, and I think it should be stateless for the sake of scalability and performance.
I also have stateful presentation layer. For example, when user fills some form and inputed values don't pass validation, it's good practice to show all fields with inputed values and to point to incorrect fields.

So, imagine that we have FooBean with methods setFoo (Foo f), getFoo () and doSave (). Bean has Session scope.
And we want to save (persist) new instance of Foo. What we do is call method setFoo () and then call method doSave (). If saving failed than user will see just filled form with all inputed values (getFoo () method is called).

That's nice, but now imagine that user clicks Create Foo link, fills all fields, tries to save but doesn't pass validation? He will see filled form again. And then he clicks on 'Create Foo' again (he wants to create 2 Foo objects simultaneously). He will see filled form with pointed errors. But it's bad, because he didn't fill this (second, new) form yet.

If we change FooBean scope to Request, than we won't be able to show filled form when it's necessary (after saving failed).

So, what is the way out? What is the correct solution? It can be JSF-specific or general.

1
Give me at least one reason not to mark you comment as 'noise, offensive or spam'. - Roman
Because he has some point ;) Although 48% isn't alwfully bad, it might drive people away from your questions, deeming you "ungrateful", for example. - Bozho
speaking strictly, there is a button "this answer is useful" as well, which also seems a bit unemployed. - Bozho
@Bozho: Well, I think that 'correct answer ticket' is here not for the sake of appreciation but rather for those people who will find this question later (from google or from local search). When I want to show that I appreciate an answer I usually write correspondent comment. I also can vote for that answer. But that's all I can do here. - Roman
while you have a point, I doubt you didn't get an appropriate answer in 50% of the cases. Commenting is no way of showing appreciation. Voting is, but you don't have too much upvotes either. - Bozho

1 Answers

1
votes

You need something called "conversation". There are a number of ways for achieving this.:

A conversation is either automatically or manually managed scope that is greater than a request, but is smaller than a session. Ideally it should store your beans as long as they are needed to be stored - i.e. in one conversation. So from your example, the first conversation will end at the point the use navigates away from the first page.

MyFaces orchestra (I can't tell for seam) can also differentiate between different browser windows/tabs.