【发布时间】:2011-08-27 14:00:29
【问题描述】:
在h:outputLink 上的onclick 事件之后,我需要将一个整数传递给JSF 支持bean。
重要提示:我不能使用 f:param 将值作为请求参数传递给导航页面,因为我正在阻止 h:outputlink 的默认 onclick 行为。 控件不是导航到由 href 属性定义的页面,而是转到一个 javascript 函数。
在 JSF 2.0 中使用 Primefaces 3.0M3 快照
我的代码如下:
<h:outputLink id="#{item.id}" value="/itemDetails.xhtml" class="itemLink" >
#{item.name}
</h:outputLink>
<script>
$(".itemLink").click(function(event) {
showDetailsInDialog();// show the item details in dialog
event.preventDefault();// prevent the behaviour provided by href
});
</script>
<h:form>
<p:remoteCommand name="showDetailsInDialog" update="itemDetailsPanel" oncomplete="itemDetailsDialog.show()">
<f:setPropertyActionListener value="....id of the item...." target="#{itemsList.selectedItem}"/>
</p:remoteCommand>
</h:form>
我有一个可重复使用的dialog,它显示从项目列表中选择的项目的详细信息。为此,当单击元素的 h:outputLink 时,需要将该项目的 id 传递给 JSF 以在 dialog 中呈现适当的内容。
如上图如果能得到remotecommand中的item的id,就可以通过setPropertyActionListener传递给合适的backing bean
【问题讨论】:
-
如果您使用 PrimeFaces,请查看
p:remoteCommand组件,它会生成一个 Javascript 函数来调用 backing-bean 方法。 -
@BheshG:谢谢!是的,我正在使用 primefaces 并且我也尝试过使用 remotecommand,但我不知道如何将值从
h:outputLink传递到f:setPropertyActionListener在p:remoteCommand内。如果您能帮助我提供一个示例代码,那就太好了! -
考虑我在 JSF 支持 bean 中有
h:outputLink中的值。 -
你能发布你的代码(视图和bean)吗?
-
@BheshG:我已经在上面发布了我的代码。谢谢!
标签: jsf jsf-2 richfaces primefaces