Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make p:graphicImage clickable and invoke bean action

I am using <p:graphicImage> like below:

<div id="mapp">
    <h3>Country Map</h3>         
    <p:graphicImage id="city"
                    value="#{countryPages_Setup.countryMap}"
                    width="250"
                    height="190">

     </p:graphicImage>                
</div>

But this is not a clickable image. How can I make this image clickable so when user click on it, I can invoke the managed bean action that I want.

like image 637
Basit Avatar asked Mar 29 '12 11:03

Basit


2 Answers

Wrap your image in a h:commandLink / h:link:

<h:commandLink action="...">
  <p:graphicImage id="city"
            value="#{countryPages_Setup.countryMap}"
            width="250"
            height="190">
  </p:graphicImage>
</h:commandLink>
like image 56
Matt Handy Avatar answered Nov 10 '22 03:11

Matt Handy


If the p:graphicImage is inside a p:contentFlow, you can use the following:

For me, this works perfectly:

<h:form id="imageFlowForm">
    <p:contentFlow id="imageContent" value="#{controller.allImages}" var="entry">
        <div class="caption">#{entry.name}</div>
        <p:commandLink styleClass="content" action="#{controller.doAction}" update="detailForm">
            <p:graphicImage value="#{entry.imagePreviewUrl}" styleClass="content" width="50px" />
            <f:param name="id" value="#{entry.id}" />
        </p:commandLink>
    </p:contentFlow>
</h:form>
like image 42
Ulrich Cech Avatar answered Nov 10 '22 05:11

Ulrich Cech