f:ajax doesn't work when parameters are passed using f:param

此生再无相见时 提交于 2019-12-05 05:03:14

问题


I am calling a method on the click of 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 parameter to the Ajax call it starts refreshing 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?


回答1:


The <f:param> has to be a child of the parent UICommand component, not of <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 as your definitions are the defaults already; plus I wonder how it's useful to send a whole IterationStatus instance as request parameter ... maybe you just wanted to send the index instead? Use #{idx.index} instead or so)

See also:

  • How can I pass selected row to commandLink inside dataTable? (although this treats <h:dataTable>, exactly the same answer applies to <ui:repeat> as well)


来源:https://stackoverflow.com/questions/11832607/fajax-doesnt-work-when-parameters-are-passed-using-fparam

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!