所以,我有两个实体:InitialSituation,其中ManytoOne与Universe实体有关。 以InitialSituation的形式,选择Universe:
<h:selectOneMenu id="universe" value="#{initialSituationController.initialSituation.universe}" >
<f:selectItems value="#{universeBean.selectItems}" />
</h:selectOneMenu>
实体(使用JPA注释):
@Entity
@Table(name = "initial_situation")
public class InitialSituation implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "initial_situation_id_seq")
@SequenceGenerator(name = "initial_situation_id_seq", sequenceName = "initial_situation_id_seq", allocationSize = 1)
@Column(name = "id_initial_situation")
protected int idInitialSituation;
protected String name;
protected String content;
protected boolean happy;
@ManyToOne
@JoinColumn(name = "id_universe")
protected Universe universe;
// Getters and setters
}
@Entity
@Table(name = "universe")
public class Universe implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="universe_id_seq")
@SequenceGenerator(name="universe_id_seq", sequenceName="universe_id_seq", allocationSize=1)
@Column( name = "id_universe" )
protected int idUniverse;
@Column
protected String name;
@Column
protected String content;
@OneToMany(mappedBy = "universe")
protected List<InitialSituation> initialSituations;
public List<InitialSituation> getInitialSituations() {
return initialSituations;
}
public void setInitialSituations(List<InitialSituation> initialSituations) {
this.initialSituations = initialSituations;
}
@Override
public String toString(){
return this.getName();
}
}
呈现的HTML中的select具有正确的值和标签。但是selectOneMenu和value =“#{initialSituationController.initialSituation.universe}”之间的绑定不起作用。 然而,我验证了InitialSituation有一个Universe,
为什么绑定不起作用?谢谢!
注意:我不能使用其他标签