【发布时间】:2018-03-27 04:01:07
【问题描述】:
我是 JSF 的新手。我有一个从 bean 获取图像列表的 c:foreach 元素。每个图像列表元素都是一个具有瞬态布尔字段的图像对象(由我创建)。该字段最初为假。我还有一个 outputText 来显示布尔值。现在我希望在单击按钮时将布尔字段设置为 true,并使用新的布尔值刷新 outputText。我试过了,但布尔值总是假的。这可能吗?似乎我设置布尔字段的图像与我获得布尔字段的位置不同,或者可能是 foreach 中的图像元素没有更新。
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>
带有JPA注解的Java Image类:
@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() 方法的普通 Java 应用程序无法证明问题,请不要使用 [java] 标记。 [java] 用户不是按照定义能够理解 JSF 问题,也不是按照定义对在他们的列表中查看 JSF 问题感兴趣。
标签: jsf foreach entity actionmethod