Send optional parameter to Ajax event listener

I have an ajax listener that should redirect to the item view page. However, since I am using the generic type as a model, I would like to further indicate in my generic data controller what constitutes a view with a second parameter.

Unfortunately, you can choose between two approaches of the listener using the event parameter , which helps to identify the object, and the second gives you the opportunity to send a free parameter , but does not have an event.

template

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

  <p:ajax event="rowSelect" listener="#{aObj.viewItem}" />
  <p:ajax event="rowSelect" listener="#{aObj.viewItem('myItemView?_id=')}" />

  ...
</p:dataTable>

controller :

public void viewItem(SelectEvent event) {
  // ...
}

public void viewItem(String viewUrl) {
  // ...
}

I can add additional properties to the bean, but since it is shared and the provision of model elements has no right to pollute it.

Is there a workaround?

+4
1

. <f:attribute name="..." value="..."/>. :

UIComponent.

UIComponent (...). , . isLiteralText() value. true, Component Map , . false, ValueExpression ValueExpression , .

, , , :

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>

:

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

Source: https://habr.com/ru/post/1652448/


All Articles