开发者

How should presentation tier (JSF) interoperate with services tier (Spring)?

开发者 https://www.devze.com 2022-12-14 14:41 出处:网络
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 o

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 ob开发者_开发百科jects 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.


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

  • MyFaces orchestra
  • JBoss seam

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消