views:

47

answers:

2

Hi,

We are using JSF in UI, Spring in business layer, Hibernate in persistence layer. Now my question is how to pass data from the JSF UI to spring business layer. Can I directly use my business object in my backing bean or should I transfer data between the layer through DTO? Can one explain me with clear explanation if possible with piece of code and that related websites?

A: 

Please read this article. It explains how you can integrate your business logic (Service) Spring beans with JSF. This article is also well written and shorter.

Article 1: http://www.javaworld.com/javaworld/jw-07-2004/jw-0719-jsf.html

Article 2: http://www.developer.com/java/ent/article.php/3602061/Spring-into-JavaServer-Faces.htm

Bytecode Ninja
+1  A: 

You question is a design question and is hence pretty broad without knowing anything specific about your project. I will only address your question about DTO vs. business object and provide a few pointer to other answers.

  • First I don't exactly know what you mean by business object. For a discussion of business object vs. entities vs. DTO vs. VO, see this answer.

  • If you use Hibernate and your business object are hibernate entities, and the presentation layer and the business layer are local, you can use the entities right in the presentation layer. This reduce boilerplate code and works fine. The problem is that if you use lazy loading, you will probably need to rely on the open session in view pattern to ensure you can lazy load data in the presentation layer. See this answer for more details.

  • If your business layer and the presentation layer are remote (which is probably not the case), that justifies the usage of DTO to transfer data between them. Also, even if everything is local, you can decide to use DTO to circumvent the problem of lazy loading. In this case, you make sure that you eager load everything that is necessary in the DTO before you pass it to the presentation layer.

That's a very high level overview, for a bit more details, see How to model in JEE.

ewernli