如何在 ajax 请求中传递 h:selectOneMenu 中更改值的附加参数?
我需要将一些参数(在我的示例中为 id)传递给 f:ajax 监听器方法,但我不知道如何传递。有人帮忙吗?
<h:form>
<!-- need to pass id value -->
<input type="hidden" name="id" id="id" value="#{id}"/>
<h:selectOneMenu value="#{visibility}">
<f:selectItems value="#{visibilities}" var="e" itemValue="#{e}" itemLabel="#{e.name}" />
<f:ajax event="valueChange" render="@form" execute="@form" listener="#{bean.updateVisibility}" />
</h:selectOneMenu>
</h:form>
豆:
class Bean {
Integer id;
public void setId() {
this.id = id;
}
public void updateVisibility(AjaxBehaviorEvent event) {
// passed id
log.debug(id);
}
}
I need to pass some parameters (id in my example) to f:ajax listener method, but i don't know how. Anybody help ?
<h:form>
<!-- need to pass id value -->
<input type="hidden" name="id" id="id" value="#{id}"/>
<h:selectOneMenu value="#{visibility}">
<f:selectItems value="#{visibilities}" var="e" itemValue="#{e}" itemLabel="#{e.name}" />
<f:ajax event="valueChange" render="@form" execute="@form" listener="#{bean.updateVisibility}" />
</h:selectOneMenu>
</h:form>
Bean:
class Bean {
Integer id;
public void setId() {
this.id = id;
}
public void updateVisibility(AjaxBehaviorEvent event) {
// passed id
log.debug(id);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它已作为请求参数发送,名称为
id
。因此,言归正传(也很怪异):如果 bean 属于请求范围,您还可以将其设为托管属性。
可能有更好的方法,具体取决于
#{id}
的实际来源,但根据问题中目前给出的信息尚不清楚。在某些情况下,您根本不需要将其作为请求参数传递。It's been sent as request parameter with the name
id
. So, to the point (and hacky):If the bean is request scoped, you can also make it a managed property.
There may be better ways depending on where the
#{id}
actually originate, which is yet unclear based on the as far given information in the question. There are namely situations where you don't need to pass it around as request parameter at all.将参数传递给 f:ajax 是通过以下方式完成的:
Passing params to f:ajax is done by: