java 带有嵌入式命令链接的 Primefaces 数据表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6011255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Primefaces dataTable with embedded commandLink
提问by c12
I'm trying to embed a Primefaces commandLink and call an action listener from a link inside a column of a Primefaces dataTable. Is this not possible? The "Test" onclick alert gets fired but it never makes it to my bean's method.
我正在尝试嵌入 Primefaces commandLink 并从 Primefaces 数据表的列内的链接调用动作侦听器。这不可能吗?“测试”onclick 警报被触发,但它永远不会进入我的 bean 的方法。
<p:dataTable var="location" value="#{adminBean.locations}">
<p:column headerText="Options">
<p:commandLink value="delete" actionListener="#{admin.deleteLocation}" onclick="alert('test')"/>
</p:column>
</p:dataTable>
bean code:
豆码:
public void deleteLocation(ActionEvent e){
//delete logic here...
}
回答by Matt Handy
This is possible. Your actionListener should be called. Keep in mind that the p:commandButton
uses ajax by default. So you should use the update
attribute in order to define the components to be updated.
这个有可能。你的 actionListener 应该被调用。请记住,p:commandButton
默认情况下使用 ajax。因此,您应该使用该update
属性来定义要更新的组件。
However, I don't know if this affects the actionListener. Did you try it with action
instead of actionListener
?
但是,我不知道这是否会影响 actionListener。你试过用action
而不是actionListener
吗?
Here is an example how I got it working:
这是我如何让它工作的一个例子:
<p:commandLink action="#{spc.selectPatient(item)}"
ajax="false"
value="Open"/>
The bean method looks as follows:
bean 方法如下所示:
public String selectPatient(Patient p) {
// do something
// return some outcome
}