如何将外键添加到JSF页面?
我试图创建一个jsf页面,显示一篇文章,用户可以在上面写评论。因此,在comment表中有一个外键引用post。 我的问题是如何将属性Idea“Idee”添加到注释“Avis”实体 这是index.xhtml如何将外键添加到JSF页面?,jsf,Jsf,我试图创建一个jsf页面,显示一篇文章,用户可以在上面写评论。因此,在comment表中有一个外键引用post。 我的问题是如何将属性Idea“Idee”添加到注释“Avis”实体 这是index.xhtml <p:outputPanel> <h:panelGrid columns="2" cellpadding="5"> <h:outputText value="#{msg['idee.titre']}"
<p:outputPanel>
<h:panelGrid columns="2" cellpadding="5">
<h:outputText value="#{msg['idee.titre']}" />
<h:outputText value="#{in.titre}" style="font-weight: bold"/>
<h:outputText value="#{msg['idee.description']}" />
<h:outputText value="#{in.description}" style="font-weight: bold"/>
<h:outputText value="#{msg['idee.theme']}" />
<h:outputText value="#{in.theme}" style="font-weight: bold"/>
<h:outputText value="#{msg['idee.type']}" />
<h:outputText value="#{in.type}" style="font-weight: bold"/>
<h:inputText value="#{avisBean.avis.commentaire}" />
<p:commandButton value="commenter" icon="ui-icon-check" action="#{avisBean.addAvis}" >
</p:commandButton>
</h:panelGrid>
</p:outputPanel>
这是Idee.java
@Entity
@Table(name = "idee")
public class Idee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column
private String titre;
@Column
private String description;
@Column
private String theme;
@Column
private String type;
@OneToMany(mappedBy = "idee")
private Collection<Avis> avis;
@ManyToOne
@JoinColumn(name="user_id")
private Utilisateur user;
@实体
@表(name=“idee”)
公共类Idee实现了可序列化{
私有静态最终长serialVersionUID=1L;
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私有int-id;
@纵队
私有弦滴度;
@纵队
私有字符串描述;
@纵队
私有字符串主题;
@纵队
私有字符串类型;
@OneToMany(mappedBy=“idee”)
私人收藏;
@许多酮
@JoinColumn(name=“user\u id”)
私人用户;
如果在一个页面中显示多个想法“idee”,则可以将“idee”对象传递给{avisBean.addAvis}
方法:
在xhtml页面中:
<p:commandButton value="commenter" icon="ui-icon-check" action="#{avisBean.addAvis(in)}" >
您的意思是将外键添加到JSF表单而不是实体中吗?
<p:commandButton value="commenter" icon="ui-icon-check" action="#{avisBean.addAvis(in)}" >
public String addAvis(Idee idee){
//add your avis to your idee here
}