正确使用支撑豆

发布于 2024-12-25 09:57:51 字数 511 浏览 2 评论 0原文

是的,我搜索了有关支持豆的问题,发现了很多问题。我读了它们,我得到了其中的一些部分,但我需要问另一个问题,抱歉。

据我了解,由于 JSF MVC 模式,需要支持 bean。支持豆是模型。因此,如果您有一个显示表单、图像和登录框的页面,则支持 bean 将为需要在视图中公开或更改的数据提供 getter/setter 对。并且支持 bean 也将具有与此相关的方法,例如提交表单、登录等时会发生什么。

所以我的问题是上面的陈述是否正确,以及您为上述组件制作的支持 bean 的数量是相关的它有多少代码?

一个支持 bean 为该页面上的所有组件公开方法和 getter/setter 对是否合法且“正确”(意味着我没有做任何错误),就像制作 3 个支持 bean 一样?每个组件一个也可以。

这一切是否都归结为经验,看看什么时候应该分离,什么时候应该为每个页面制作一个支持 bean,以及它的逻辑部分?我听说有人为页面上的每个组件制作了一个支持 bean,但听起来您最终会得到很多小类。

如果有人能够验证并纠正我,我将不胜感激。

Yes, I searched for questions about backing beans and I found many questions. I read them, and I get some parts of it but I need to ask another question, sorry.

After what I understand backing beans are needed because of JSF MVC pattern. Backing beans are the model. So if you have a page that displays a form, an image and a login box the backing beans will have getter/setter pairs for the data that needs to be exposed or changed in the view. And the backing beans will also have methods related to this such as what happen when you submit the form, login in etc.

So my question is if the statements above is correct, and the number of backing beans you make for the components above is dependent on how much code it is?

Would one backing bean exposing methods and getter/setter pairs for all components on this page be legal and "correct" (meaning that I don't do any wrong) in the same way as making 3 backing beans; one for each component would also be fine.

Does it all boil down to experience to see when you should separate vs. making one backing bean for each page, and also the logical part of it? I heard one guy made a backing bean for each component on the page but it sounds like you end up with a lot of small classes.

I would highly apprciate if somebody could verify and correct me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风柔一江水 2025-01-01 09:57:51

将视图中的所有组件绑定到一个托管 bean 的属性和操作是合法的。 IDE 工具可能会鼓励您使用单个支持 bean 来完成此操作。

然而,从类的角度来看,这种方法缺乏粒度,并且可能使托管 bean 难以测试。如果一个班级没有明确定义的目的,那么很难断言他们正在做这项工作。 请参阅警告标志“总结课程所做的内容包括单词“和””。所有版本的 JSF 都支持依赖注入,因此依赖组合来组装托管 bean 相对容易。

这是一个有点主观的话题,答案取决于其他因素(应用程序规模;视图设计;页面功能。)

It is legal for all components in a view to be bound to one managed bean for properties and actions. IDE tooling may encourage you to do this with a single backing bean.

From a class point of view however this approach lacks granularity and can make the managed beans difficult to test. If a class doesn't have a clearly defined purpose then it can be difficult to assert they are doing that job. See warning sign "Summing up what the class does includes the word “and”". All versions of JSF support dependency injection so it is relatively easy to rely on composition to assemble your managed beans.

This is a somewhat subjective topic and the answer depends on other factors (application scale; view design; page function.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文