2013-10-10 36 views
2

我不願意擁有自己的圖像和圖像。默認情況下,不顯示graphicimage。如果用戶點擊按鈕,則顯示圖形圖像(呈現=真)。Primefaces:GraphicImage不刷新

我可以做到,但我必須刷新頁面才能看到顯示的圖像。

我想我必須使用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; 
    } 
} 

回答

2

我發現這個問題:我包圍我graphicImage的組件與面板組件,使用id =「面板」;並將我的更新屬性修改爲update =「panel」。現在,圖片直接顯示。

0

graphicImagecommandButton之外,在按鍵聲明 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> 
+0

我做到了,但結果沒有改變:頁面需要刷新才能看到圖片。我在tomcat控制檯中沒有錯誤。 –

+0

我更新了我的答案。我沒有看到你使用action而不是actionListener。這可能是一個問題。另外我想知道你的代碼是否輸入了'affichePhotoGenerique'方法。使用調試工具來查看 –

+0

我用actionListener替換了action,但沒有更改。通過調試,我看到它正在進入「affichePhotoGenerique」方法。我也使用Chrome的JavaScript控制檯,並沒有錯誤。 –