3

我想要一个按钮和一个图形图像。默认情况下,图形图像不显示。如果用户单击按钮,则显示图形图像(rendered = true)。

我可以做到,但我必须刷新页面才能看到显示的图形图像。

我想我必须使用 ajax 组件在单击按钮时直接显示,但我没有设法正确使用它。你能指导我吗?

html:

<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>

托管豆:

@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;
    }
}
4

2 回答 2

2

我发现了问题:我用一个面板组件包围了我的图形图像组件, id="panel" ;并将我的更新属性修改为 update="panel" 。现在,图片直接显示。

于 2013-10-13T15:04:47.560 回答
0

graphicImage外面的commandButton和里面的按钮声明 update = 'photoGenerique'。像这样:

<h:form>
 <p:commandButton value="Prendre la photo générique" update="photoGenerique"
            id="boutonPhotoGenerique" icon="ui-icon-image"
            actionListener="#{defaultCommandBean.affichePhotoGenerique}">

 </p:commandButton>
<p:graphicImage id="photoGenerique"
                rendered="#{defaultCommandBean.rendered}"
                value="photos/photo_generique.jpg" />
</h:form>
于 2013-10-10T20:41:57.913 回答