我想要一个按钮和一个图形图像。默认情况下,不显示图形图像。如果用户单击该按钮,则会显示图形图像(呈现 = 真)。
我可以做到,但我必须刷新页面才能看到显示的图形图像。
我想我必须使用 ajax 组件来在单击按钮时直接显示,但我没能正确地使用它。你能指导我吗?
xhtml :
<h:body>
<h:form>
<p:commandButton value="Prendre la photo générique"
id="boutonPhotoGenerique" icon="ui-icon-image"
action="#{defaultCommandBean.affichePhotoGenerique}">
<p:graphicImage id="photoGenerique"
rendered="#{defaultCommandBean.rendered}"
value="photos/photo_generique.jpg" />
</p:commandButton>
</h:form>
</h:body>
托管 Bean:
@ManagedBean(name = "defaultCommandBean")
@SessionScoped
public class DefaultCommandBean {
private boolean rendered;
public boolean isRendered() {
return rendered;
}
public void setRendered(boolean rendered) {
this.rendered = rendered;
}
public void affichePhotoGenerique() {
rendered = true;
}
}
最佳答案
我发现了问题:我用一个面板组件包围了我的 graphicImage 组件,id="panel";并将我的更新属性修改为 update="panel"。现在,图片直接显示出来了。
关于ajax - 素面 : GraphicImage does not refresh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19305719/