ActionListener 和使用 ajax 从数据网格内面板内的按钮更新 DataGrid 不起作用

发布于 2024-12-09 05:05:04 字数 2540 浏览 0 评论 0原文

我有这个 xhtml 代码:

<p:dataGrid id="dgData"
    columns="1"
    rows="100"
    value="#{myStickiesController.items}"
    var="sticky">
    <p:panel header="From :#{sticky.users.displayName}" rendered="#{eventstickiesController.eventSticky}" binding="#{eventstickiesController.eventPanel}">
        <f:attribute name="stickyId" value="#{sticky.stickyID}" ></f:attribute>
        <h:panelGrid columns="2">
            <p:graphicImage value="#{imageStreamer.fileContent}" style="width:50px; height: 50px" alt="No Profile Image">
                <f:param id="uid" name="uid" value="#{sticky.users.userID}" />
            </p:graphicImage>
            <h:outputLabel value="Event Info : #{eventstickiesController.content}" binding="#{eventstickiesController.outputLabel}">
                <f:attribute name="stickyId" value="#{sticky.stickyID}" ></f:attribute>
            </h:outputLabel>
        </h:panelGrid>
        <f:facet name="footer">
            <p:commandButton image="/images/buttons/Delete.gif"
                             actionListener="#{myStickiesController.deleteSticky}"
                             action="#{snippetsStickyEditorLinkerBean.updateSnippetLink}"
                             update="dgData" >
                <f:attribute name="stickyId" value="#{sticky.stickyID}" ></f:attribute>
                <f:param  name="pageViewId" value="Default"/>
            </p:commandButton>
        </f:facet>
    </p:panel>
</p:dataGrid>

actionListener 类的代码:

public class MyStickiesController {
public void deleteSticky(ActionEvent ae)
{
    Long sid = (Long)ae.getComponent().getAttributes().get("stickyId");
    Stickies s = ejbFacade.find(sid);
    List<Recipients> rl = s.getRecipientsList();
    DBConnectionProxyUser sbcpu = new DBConnectionProxyUser();
    Users currentUser = sbcpu.getConnectedUser(ejbUsersFacade);
    for (Recipients r:rl)
    {
        if (currentUser.getUserID()==r.getUsers().getUserID())
        {
            r.setDisplay(Boolean.FALSE);
        }
    }       
}
}

现在,如果我将命令按钮放在 p:dataGrid 内,则 dataGrid 会更新并且 actionListener 会工作。如果我将按钮放在 dataGrid 中,则 dataGrid 不会更新并且 actionListener 不起作用。

我尝试用 p:outputPanel 包装整个内容,但 actionListener 不起作用。

ActionEvent 是 javax.faces.event.ActionEvent 我正在使用 Mojarra 2.1.3 和 primefaces 2.2.1、Glassfish 3.0.1 和 Netbeans 6.9.1

提前致谢...

I have this xhtml code:

<p:dataGrid id="dgData"
    columns="1"
    rows="100"
    value="#{myStickiesController.items}"
    var="sticky">
    <p:panel header="From :#{sticky.users.displayName}" rendered="#{eventstickiesController.eventSticky}" binding="#{eventstickiesController.eventPanel}">
        <f:attribute name="stickyId" value="#{sticky.stickyID}" ></f:attribute>
        <h:panelGrid columns="2">
            <p:graphicImage value="#{imageStreamer.fileContent}" style="width:50px; height: 50px" alt="No Profile Image">
                <f:param id="uid" name="uid" value="#{sticky.users.userID}" />
            </p:graphicImage>
            <h:outputLabel value="Event Info : #{eventstickiesController.content}" binding="#{eventstickiesController.outputLabel}">
                <f:attribute name="stickyId" value="#{sticky.stickyID}" ></f:attribute>
            </h:outputLabel>
        </h:panelGrid>
        <f:facet name="footer">
            <p:commandButton image="/images/buttons/Delete.gif"
                             actionListener="#{myStickiesController.deleteSticky}"
                             action="#{snippetsStickyEditorLinkerBean.updateSnippetLink}"
                             update="dgData" >
                <f:attribute name="stickyId" value="#{sticky.stickyID}" ></f:attribute>
                <f:param  name="pageViewId" value="Default"/>
            </p:commandButton>
        </f:facet>
    </p:panel>
</p:dataGrid>

the code of the actionListener class:

public class MyStickiesController {
public void deleteSticky(ActionEvent ae)
{
    Long sid = (Long)ae.getComponent().getAttributes().get("stickyId");
    Stickies s = ejbFacade.find(sid);
    List<Recipients> rl = s.getRecipientsList();
    DBConnectionProxyUser sbcpu = new DBConnectionProxyUser();
    Users currentUser = sbcpu.getConnectedUser(ejbUsersFacade);
    for (Recipients r:rl)
    {
        if (currentUser.getUserID()==r.getUsers().getUserID())
        {
            r.setDisplay(Boolean.FALSE);
        }
    }       
}
}

Now, if I put the command button that is inside the p:dataGrid, the dataGrid is updated and the actionListener works. If I put the button inside the dataGrid, the dataGrid is not updated and the actionListener doesn't work.

I tried wrapping thw whole thing with p:outputPanel, and the actionListener doesn't work.

The ActionEvent is javax.faces.event.ActionEvent
I am using Mojarra 2.1.3 with primefaces 2.2.1, Glassfish 3.0.1 and Netbeans 6.9.1

Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

用心笑 2024-12-16 05:05:04

我设法让它工作......

该解决方案呈现为两部分:

  1. 我将 Glassfish Mojarra 模块更新到 2.1.3

  2. 我添加了 ap:在要渲染内部代码片段的情况下,将渲染remotecommamd 和 ap:outputpanel。其他代码片段很容易渲染。

我希望这对某人有帮助......

I managed to make it work...

The solution renders into 2 parts:

  1. I updated the Glassfish Mojarra Module to 2.1.3

  2. I added a p:remotecommamd and a p:outputpanel to be rendered in case the inner snippet is to be rendered. Other snippets are easy to be rendered.

I hope this one helps somebody...

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