Praveen V
Praveen V

Reputation: 267

How to add action for h:graphicImage Primefaces

Hi I have a graphicalImage and I want a method in the backingBean to be fired up on clicking on the image.Below is the code snippet that i am using but it is not working. Please help.

<h:graphicImage value="../resources/images/delete_button.png"
onclick="editBean.deleteStudyPlan"
style="float:center;height: 18px; width:20px;"
title="Delete the studyplan"/>

Upvotes: 2

Views: 16184

Answers (1)

BalusC
BalusC

Reputation: 1108642

You need to wrap it in a <h:commandLink> or <p:commandLink> and specify the action there.

<h:commandLink action="#{editBean.deleteStudyPlan}">
    <h:graphicImage ... />
</h:commandLink>

Alternatively, you can just specify the image as a CSS background image of the command link or button.

The onclick surely isn't a method expression to a JSF backing bean action method. It's a JavaScript function handler. JavaScript is an entirely different language which runs in the webbrowser, working on the HTML code produced by JSF.

Upvotes: 10

Related Questions