如何为单页设计布局 beans
嘿伙计们。我正在设计一个使用 Icefaces 框架的网站。我一直在读一本叫做《真实世界 Java EE 模式》的书。我有点困惑如何布局页面。通常我只会有一个 POJO 类来实现 bean 的可序列化。然后这个 Bean 将支持每个页面。通过单页面设计,我将在页面上放置一堆元素。数据表、树、输入、日历等。为每个数据表、日历等使用单独的 bean 或将其全部放入一个 bean 中是正常还是最佳实践?我不知道如何解决这个问题。现在每个元素都是一个 bean,我使用 @Inject 注释让数据表与树对话,反之亦然。这会创建非常糟糕的代码,如果我将其作为类的成员,我将得到循环引用,因为数据表 bean 必须注入日历,而日历必须注入数据表。
感谢您的任何帮助。
Hey guys. I'm designing a site that uses the Icefaces framework. I've been reading a book called Real World Java EE patterns. I'm kind of confused how to layout the pages. Normally I would have just a POJO class implement serializable for a bean. This bean would then back each page. With a single page design I'm going to have a bunch of elements on the page. Datatables, trees, inputs, calendars etc. Is it normal or best practice to have separate beans for each datatable, calendar, etc or put that all in one bean? I'm not sure how to approach this. Right now each element is a bean and I'm using the @Inject annotation to have the data table talk to the tree and vise versa. This creates really bad code and if I put this as a member of the class I will get a circular reference because the data table bean has to inject the calendar and the calendar has to inject the data table.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我倾向于每个
或至少每个视图(XHTML/JSP 文件)使用一个 bean。任何相关的 bean 都将被注入到这个特定的“主”bean 中(因此不会相互注入)。I tend to use a single bean per
<h:form>
or at least per view (XHTML/JSP file). Any related beans will just be injected in this particular "main" bean (and thus not among each other).