将 JSF2 管理的 pojo bean 传递到 EJB 中或将所需内容放入传输对象中
目前我正在从 JSF 2
调用 EJB 3
会话 Bean。但是,我不确定是否应该将 JSF 托管 bean 传递到 EJB 中?
假设表单上的任何内容(以及支持 bean)都是我通过 EJB 层持久保存所需的一切,我是否应该手动将所有属性克隆到传输对象中,或者是否有更好的方法来执行此操作?
POJO
的支持 bean 大量使用 JSF 生命周期标记(例如 @ManagedBean
)进行注释,并且驻留在 Web 项目
中,而 EJB 则单独驻留在 EJB 项目
中。
Currently i am calling EJB 3
Session Beans from JSF 2
. However, i am not sure if i should be passing JSF managed beans into EJB?
Assuming that whatever on the form (and thus the backing bean) was everything i needed to persist through the EJB layer, should i clone out all the attributes by hand into a transfer object, or is there a better way of doing this?
The backing bean though POJO
is heavily annotated with JSF lifecycle tags (Such as @ManagedBean
) and resides in the Web project
while the EJBs reside separately in the EJB project
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来好像您已将模型与控制器紧密耦合,如大多数基本 JSF 教程中所示。您应该将模型从控制器中解耦到它自己的类中。当您使用 EJB 时,您很有可能也在使用 JPA(否则 EJB 对持久性如何真正有用?),您可以只使用现有的 JPA
@Entity
类作为模型。例如,
与
which 一起用作
It sounds like as if you've tight-coupled the model with the controller like as shown in most basic JSF tutorials. You should decouple the model from the controller into its own class. As you're using EJBs, the chance is big that you're also using JPA (how else would EJBs be really useful for persistence?), you can just use the existing JPA
@Entity
class as model.E.g.
with
which is to be used as
我试图对 CDI 执行相同的操作,主要区别(不包括使用
@Named
而不是@ManagedBean
)是我必须在 Controller 类中初始化我的传输对象。而不是
:
private Product Product;
,因此,我必须使用
:
private Product Product = new Product();
也许它会对某人有所帮助:)
I was trying to do the same with CDI and the main diffrence (excluding using
@Named
instead of@ManagedBean
) was that I had to initialize my transport object in the Controller class.So instead of:
private Product product;
I had to use:
private Product product = new Product();
Maybe it will help someone :)