ActionListener 和使用 ajax 从数据网格内面板内的按钮更新 DataGrid 不起作用
我有这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法让它工作......
该解决方案呈现为两部分:
我将 Glassfish Mojarra 模块更新到 2.1.3
我添加了 ap:在要渲染内部代码片段的情况下,将渲染remotecommamd 和 ap:outputpanel。其他代码片段很容易渲染。
我希望这对某人有帮助......
I managed to make it work...
The solution renders into 2 parts:
I updated the Glassfish Mojarra Module to 2.1.3
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...