3

I waant to have abutton and a graphicimage. By default, the graphicimage is not displayed. If the user click on the button, the graphic image is displayed (rendered = true).

I can do it but I have to refresh the page to see the graphicimage displayed.

I think I have to use ajax component to make the displaying directly when the button is clicked but I don't manage to use it corectly. Could you guide me?

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>

Managed 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;
    }
}
miroslav_mijajlovic
  • 1,703
  • 17
  • 31
clement M.
  • 141
  • 2
  • 9

2 Answers2

2

I found the problem : I surrounded my graphicImage component with a panel component, with id="panel" ; and modified my update attribute to update="panel" . Now, the picture is directy displayed.

clement M.
  • 141
  • 2
  • 9
0

Put the graphicImage outside the commandButton and in button declare update = 'photoGenerique'. Like this:

<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>
miroslav_mijajlovic
  • 1,703
  • 17
  • 31
  • I did it but the result is unchanged : the page needs to be refreshed to see the picture. I have no error in tomcat console. – clement M. Oct 10 '13 at 20:53
  • I've updatem my answer. I haven;t seen that you used action instead of actionListener. This could be a problem. Also I want to know if your code enters the method `affichePhotoGenerique`. Use debugging tool to see that – miroslav_mijajlovic Oct 11 '13 at 06:25
  • I replaced action by actionListener but no change. With debugging, I saw that it's entering into the "affichePhotoGenerique" method. I also used Chrome javascript console and there is no error. – clement M. Oct 11 '13 at 14:25