Add additional parameter to JSF Ajax event listener

You could set an attribute in your data table and read it in your select listener. To do so, use <f:attribute name="..." value="..."/>. From the documentation:

Constraints

Must be nested inside a UIComponent custom action.

Description

Locate the closest parent UIComponent custom action instance (…). If the associated component already has a component
attribute with that name, take no action. Otherwise, call the isLiteralText() method on the argument value. If it
returns true, store the value in the component’s attribute Map under the name derived above. If it returns false, store
the ValueExpression in the component’s ValueExpression Map under the name derived above.

So, taking the attribute you tried to set in your comment, you should use it like:

XHTML:

<p:dataTable value="#{aObj.objList}" var="item" .... selectionMode="single">

  <f:attribute name="test" value="abc" />
  <p:ajax event="rowSelect" listener="#{aObj.viewItem}" />

  ...
</p:dataTable>

Listener:

public void viewItem(SelectEvent event) {
  String test = (String) event.getComponent().getAttributes().get("test");
  // ...
}

Leave a Comment