Ajax Primefaces:GraphicImage不刷新

Ajax Primefaces:GraphicImage不刷新,ajax,primefaces,Ajax,Primefaces,我想要一张照片和一张图片。默认情况下,不显示图形图像。如果用户单击按钮,将显示图形图像(rendered=true) 我可以这样做,但我必须刷新页面才能看到显示的图形图像 我想我必须使用ajax组件在单击按钮时直接显示,但我无法正确使用它。你能指引我吗 xhtml: <h:body> <h:form> <p:commandButton value="Prendre la photo générique" id="bou

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

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

我想我必须使用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>

graphicImage
置于
commandButton
之外,并置于按钮declare中
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>


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

我这样做了,但结果没有改变:页面需要刷新才能看到图片。我在tomcat控制台中没有错误。我已经更新了我的答案。我没有;我没看到你用action而不是actionListener。这可能是个问题。我还想知道您的代码是否输入了方法
affichePhotoGenerique
。使用调试工具查看我用actionListener替换了action,但没有更改。通过调试,我看到它进入了“affichePhotoGenerique”方法。我还使用了ChromeJavaScript控制台,没有错误。
<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>