JSF - p:dataTable - p:commandButton 即使在 p:column 内也不起作用

发布于 2024-10-09 21:53:11 字数 738 浏览 0 评论 0原文

我在数据表中有一个命令按钮。然而,当我点击“动作”时,它不会被调用(与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

作妖 2024-10-16 21:53:11

我将您的按钮列代码添加到我现有的按钮列代码中,并通过支持 bean 添加了一个虚拟方法。当我按下按钮时,该方法会被正确调用,它会正常工作。下面是我添加到 dataTable 中的代码:

<p:column>
    <p:commandButton value="Go" id="actionButton" action="#{tableBean.buttonAction()}" />
</p:column>

这是我的支持 bean 中的 buttonAction 方法:

public void buttonAction()
    {
        int a = 0;
        for(int i = 0; i < 100; i++)
            a = i;
    }

我在这个方法上放置了一个断点,所以我知道当我单击按钮时它会被调用。
我更进一步,使用了您的数据表代码(带有我的数据源),当我按下按钮时,该方法仍在被调用。我不知道你正在使用什么开发环境,但如果它有调试模式,请在你的 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:

<p:column>
    <p:commandButton value="Go" id="actionButton" action="#{tableBean.buttonAction()}" />
</p:column>

Here is the buttonAction method in my backing bean:

public void buttonAction()
    {
        int a = 0;
        for(int i = 0; i < 100; i++)
            a = i;
    }

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.

苦行僧 2024-10-16 21:53:11

我认为你必须更改为:

<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:dataTable>
<p:commandButton value="Go" id="actionButton" action="#{myBean.doAction}" />
</h:form>

我认为你不能在数据表中拥有按钮。试试这个。

I think you have to change to:

<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:dataTable>
<p:commandButton value="Go" id="actionButton" action="#{myBean.doAction}" />
</h:form>

I don't think you can have the button inside the dataTable. Try this.

苏辞 2024-10-16 21:53:11

请参阅此示例 - 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

剩余の解释 2024-10-16 21:53:11

我遇到了同样的问题,在尝试了不同的方法后,我通过在 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 the p:datatable) in the init method of the Bean.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文