使用f:param传递参数时,f:ajax不起作用 [英] f:ajax doesn't work when parameters are passed using f:param
问题描述
点击链接,我正在调用一个方法.以下代码可以正常工作
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>
但是当我尝试将参数传递给Ajax调用时,它将开始刷新整个页面
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>
此代码有什么问题?
推荐答案
<f:param>
必须是父UICommand
组件的子元素,而不是<f:ajax>
的子元素.
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>
(请注意,由于您的定义已经是默认值,因此我删除了execute
和event
属性;此外,我想知道发送整个IterationStatus
实例作为请求参数的用处如何……也许您只是想发送索引呢?或者使用#{idx.index}
代替)
(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)
- 我如何传递所选内容(尽管它对待
<h:dataTable>
,但对<ui:repeat>
也完全一样)
- 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)
这篇关于使用f:param传递参数时,f:ajax不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!