views:

99

answers:

1

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  A: 

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 nagivates away from the first page.

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

Bozho
I'll google on it, thanks.
Roman
One more way I found is to use Spring WebFlow. But in my project I used MyFaces orchestra. A big plus of orchestra is that only few things should be added/changed in the project to integrate Orchestra.
Roman