I need to pass an integer to a JSF backing bean after onclick
event on h:outputLink
.
Important : I cannot use f:param to pass value as request parameters to the naviagating page as I am preventing default onclick behaviour of h:outputlink. The control instead of navigating to page defined by href attribute, goes to a javascript function.
Using Primefaces 3.0M3 snapshot with JSF 2.0
My code follows:
<h:outputLink id="#{item.id}" value="/itemDetails.xhtml" class="itemLink" >
#{item.name}
</h:outputLink>
<script>
$(".itemLink").click(function(event) {
showDetailsInDialog();// show the item details in dialog
event.preventDefault();// prevent the behaviour provided by href
});
</script>
<h:form>
<p:remoteCommand name="showDetailsInDialog" update="itemDetailsPanel" oncomplete="itemDetailsDialog.show()">
<f:setPropertyActionListener value="....id of the item...." target="#{itemsList.selectedItem}"/>
</p:remoteCommand>
</h:form>
I have a reusable dialog
that displays the details of item selected from a itemslist. For this when the h:outputLink
for an element is clicked the id of that item needs to be passed to JSF to render appropriate content in dialog
.
As shown above If I can get the id of item in remotecommand
, I can pass it to appropriate backing bean through setPropertyActionListener