F: ajax does not work when parameters are passed using the f: param parameter

I call the method by clicking the link. The following code works ajaxfully

<ui:repeat value="#{myBean.names}" var="name" varStatus="idx"> <li> <h:commandLink value="#{name.label}"> <f:ajax execute="@this" event="click" render="@all" listener="#{myBean.changeActiveName}" > </f:ajax> </h:commandLink> </li> </ui:repeat> 

But when I try to pass the parameter to an Ajax call, it starts to refresh the whole page

  <ui:repeat value="#{myBean.names}" var="name" varStatus="idx"> <li> <h:commandLink value="#{name.label}"> <f:ajax execute="@this" event="click" render="@all" listener="#{myBean.changeActiveName}" > <f:param name="idx" value="#{idx}" /> </f:ajax> </h:commandLink> </li> </ui:repeat> 

What is wrong with this code?

+2
source share
1 answer

<f:param> should be a child of the parent component of UICommand , not <f:ajax> .

 <h:commandLink value="#{name.label}"> <f:param name="idx" value="#{idx}" /> <f:ajax listener="#{myBean.changeActiveName}" render="@all" /> </h:commandLink> 

(note that I removed the execute and event attributes, since your definitions are already default values, plus I wonder how useful it is to send the entire instance of IterationStatus as a query parameter ... maybe you just wanted to send the index instead: use #{idx.index} instead)

See also:

+4
source

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


All Articles