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

时间:2011-10-12 13:41:41

标签: ajax jsf-2 primefaces

我有这个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

提前致谢...

1 个答案:

答案 0 :(得分:1)

我设法让它发挥作用......

解决方案分为两部分:

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

  2. 我添加了一个p:remotecommamd和一个p:outputpanel,以便在呈现内部片段时进行渲染。其他片段很容易呈现。

  3. 我希望这个能帮助某人......