JSF - p:dataTable - p:commandButton 即使在 p:column 内也不起作用
我在数据表中有一个命令按钮。然而,当我点击“动作”时,它不会被调用(与actionListener效果相同);我在服务器操作开始时添加了日志,但它从未显示。 请注意,该按钮在数据列表之外时可以正常工作。
这是我的代码:
<h:form id="compSearchForm">
<p:dataTable var="competency" value="#{competencySearchBean.matchingCompetencies.toArray()}">
<p:column>
<f:facet name="header">
<h:outputLabel value="Title" />
</f:facet>
<h:outputText value="#{competency.title}" />
</p:column>
<p:column>
<p:commandButton value="Go" id="actionButton" action="#{myBean.doAction}" />
</p:column>
</p:dataTable>
</h:form>
您知道问题可能是什么吗?
I have a commandButton inside a DataTable. However the "action" isn't called when I click on it (same effect with an actionListener); I added logs at the beginning of the server action, and it never shows.
Please note that the button works fine when outside from the datalist.
Here is my code:
<h:form id="compSearchForm">
<p:dataTable var="competency" value="#{competencySearchBean.matchingCompetencies.toArray()}">
<p:column>
<f:facet name="header">
<h:outputLabel value="Title" />
</f:facet>
<h:outputText value="#{competency.title}" />
</p:column>
<p:column>
<p:commandButton value="Go" id="actionButton" action="#{myBean.doAction}" />
</p:column>
</p:dataTable>
</h:form>
Would you have any idea as to what the issue might be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我将您的按钮列代码添加到我现有的按钮列代码中,并通过支持 bean 添加了一个虚拟方法。当我按下按钮时,该方法会被正确调用,它会正常工作。下面是我添加到 dataTable 中的代码:
这是我的支持 bean 中的 buttonAction 方法:
我在这个方法上放置了一个断点,所以我知道当我单击按钮时它会被调用。
我更进一步,使用了您的数据表代码(带有我的数据源),当我按下按钮时,该方法仍在被调用。我不知道你正在使用什么开发环境,但如果它有调试模式,请在你的 doAction 方法上放置一个断点,并在你的 bean 中的其他一些战略位置上放置一个断点,然后在调试模式下运行你的项目以查看发生了什么。
I added your button column code to an existing of mine along with a dummy method in by backing bean. The method is called correctly when I press the button it works correctly. Here is the code I added to my dataTable:
Here is the buttonAction method in my backing bean:
I put a breakpoint on this method, so I know it is getting called when I click the button.
I went a step further and used your datatable code (with my data source) and the method is still being called when I press the button. I don't know what development environment you are using, but if it has a debug mode put a breakpoint on your doAction method, and a few other strategic locations in your bean, then run your project in debug mode to see what is going on.
我认为你必须更改为:
我认为你不能在数据表中拥有按钮。试试这个。
I think you have to change to:
I don't think you can have the button inside the dataTable. Try this.
请参阅此示例 - http://www.primefaces.org/showcase/ui/datatableRowSelectionByColumn.jsf
我认为你必须在 id 前面加上表单 ID,
看看它如何更新“:form:display”,而不仅仅是“display”
对我有用
see this example - http://www.primefaces.org/showcase/ui/datatableRowSelectionByColumn.jsf
I think you must prefix the id with the form ID
see how it updates ":form:display" instead of only "display"
worked for me
我遇到了同样的问题,在尝试了不同的方法后,我通过在
init 中初始化我的
方法。List
(我在p:datatable
中使用的列表)解决了这个问题Bean
的使用此表单,列表将转到包含某些值的页面。
即使我将
List放入myList = new ArrayList();
它不起作用。我必须在列表中放入一些值。这是解决问题的唯一方法。
I had the same problem and after trying different ways, I resolved it by initializing my
List
(the list that I use in thep:datatable
) in theinit
method of theBean
.With this form, the list goes to the page with some values.
Even when I put
List<Paciente> myList = new ArrayList<Paciente>();
it didn't work.I have to put some values in the list. That was the only way that resolved the problem.