我是JSF的新手。我有一个c:foreach元素从bean获取图像列表。每个图像列表元素都是一个Image对象(由我创建),它具有一个临时布尔字段。该字段最初是错误的。我也有一个outputText来显示布尔值。现在我想要点击一个按钮时,boolean字段被设置为true,并且outputText用新的布尔值刷新。我试过,但布尔值总是假。这可能吗?它看起来像我设置布尔字段的图像不一样,我得到布尔字段,或者foreach中的图像元素没有更新。里面c:foreach设置JPA实体的瞬态字段并检索它
JSF代码:
<c:forEach items="#{publicGalleryImageShowController.images}" var="img">
<h:form>
<h:commandButton
action="#{img.setShowComments(true)}"
value="Show/Hide">
<f:ajax render="co-#{img.id}" />
</h:commandButton>
</h:form>
<h:panelGroup id="co-#{img.id}">
<h:outputText value="#{img.showComments}" />
</h:panelGroup>
</c:forEach>
Java图像类JPA注释:
@Entity
public class Image {
private boolean showComments;
/*other fields*/
@Transient
public boolean isShowComments() {
return showComments;
}
public void setShowComments(boolean showComments) {
this.showComments = showComments;
}
/*other getters and setters*/
}
对未来的JSF问题的建议:只要问题不能用简单的使用main()方法的vanilla Java应用程序来证明,请不要使用[java]标记。 [java]用户不是每个定义都能够理解JSF问题,也不是每个定义都有兴趣在他们的列表中看到JSF问题。 – BalusC