JSF data transfer between UI and business layer
We are using JSF in UI, Spring in business layer,开发者_StackOverflow社区 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?
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 Java EE.
精彩评论