[英]updating different jpa entities from a single html form (jsf page)
我一直在审查一些在线发布的示例,它们都执行简单的CRUD。
1 jsf page = 1 entity = 1 table.
大多数时候,这就是我所看到的。 但是如果您只有1个带有1个表单的jsf页面,并且需要将数据提供给3个实体,该怎么办? 具有诸如姓名,公司和爱好的表格字段。
他们的价值需要放在实体上
person.name, work.company_name and other_info.hobby.
这是通过绑定自动完成的吗? 还是我们需要手动分配值? 请说明一下,我现在有点困惑
我不确定是否看到问题。 您可以使它们成为同一个支持bean的属性:
@ManagedBean
@ViewScoped
public class Profile {
private Person person;
private Work work;
private OtherInfo otherInfo;
// ...
}
同
<h:inputText value="#{profile.person.name}" />
<h:inputText value="#{profile.work.companyName}" />
<h:inputText value="#{profile.otherInfo.hobby}" />
或者,如果Work
和OtherInfo
与Person
具有@OneToOne
关系(在现实世界中,它们无疑具有):
@ManagedBean
@ViewScoped
public class Profile {
private Person person; // Has in turn Work and OtherInfo properties.
// ...
}
同
<h:inputText value="#{profile.person.name}" />
<h:inputText value="#{profile.person.work.companyName}" />
<h:inputText value="#{profile.person.otherInfo.hobby}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.