如何模拟此行为
<h:selectOneMenu id="idMovie" value="#{comments.comments.idMovie}" title="IdMovie" required="true" requiredMessage="The idMovie field is required." >
<f:selectItems value="#{movies.movieItemsAvailableSelectOne}"/>
</h:selectOneMenu>
<h:selectOneMenu id="idUser" value="#{comments.comments.idUser}" title="IdUser" required="true" requiredMessage="The idUser field is required." >
<f:selectItems value="#{user.userItemsAvailableSelectOne}"/>
</h:selectOneMenu>
以某种方式
<h:SOMETHING id="idMovie" ´valueToCommit´="#{comments.comments.idMovie}" ´valueToGet´="#{movies.movies}"/>
<h:SOMETHING id="idUser" ´valueToCommit´="#{comments.comments.idUser}" ´valueToGet´="#{user.userSession.user}"/>
movies.movie拥有我需要的当前对象 user.userSession.user也是如此,但我不知道如何将它们传递给comments.commment.idMovie(属于Movie类型)来提交
提前致谢
最好的问候 伊格纳西奥答案 0 :(得分:0)
这在commentController的构造函数中;
userController = (UserController) facesContext.getApplication().evaluateExpressionGet(facesContext, "#{user}", UserController.class);
movieController = (MovieController) facesContext.getApplication().evaluateExpressionGet(facesContext, "#{movie}", MoviesController.class);
加(在声明中)
private MovieController movieController = null;
private Comment comment = null;
private UserController userController = null;
和
public String create() {
try {
utx.begin();
} catch (Exception ex) {
}
try {
Exception transactionException = null;
comment.setUserId(userController.getUser());
comment.setMovieId(movieController.getMovie());
jpaController.create(comment); ...Default Facade class
try {
utx.commit();
} catch (javax.transaction.RollbackException ex) {
transactionException = ex;
} catch (Exception ex) {
}...
...
诀窍!!!!!!!!!!