JSF backing bean structure (best practices)

后端 未结 6 785
谎友^
谎友^ 2020-11-28 00:21

I hope that in this post, I can get people\'s opinions on best practices for the interface between JSF pages and backing beans.

One thing that I never can settle on

6条回答
  •  感情败类
    2020-11-28 00:48

    I might not answer your every question, because few seems quite dependent on case to case.

    • This is fine to have a business logic in your backing bean. It depends where are you coming from. If you are practicing domain driven design, you will be tempted to include the business logic in to backing bean or may be persistence logic as well. They argue that why so dumb object. Object should carry not just state but behavior too. On the other hand if you consider traditional Java EE way of doing things, you might be feeling like having data in your backing bean, which also can be your entity bean, and other business and persistence logic in some session bean or something. That is fine too.

    • Its perfectly fine to have single backing bean for the whole page. I don't see any problem with this alone. This might not look right, but that depends on the case.

    • Your other question is far more dependent on case you are having in hand. I would prefer to go domain driven here, it might be appropriate to add properties to the existing or otherwise create a new bean for that. Which ever suits better. I don't think there is any silver bullet for this.

    • Which properties belongs to which backing bean. Well, is it not depend on the domain object? Or may be the question is not that clear.

    Moreover, in your given code example, I am not seeing any huge benefit.

提交回复
热议问题