Primefaces Ajax 操作未触发更新
我有下面的页面,一切正常...
除了在我单击删除按钮并在确认对话框中点击“是的”之后,我的页面不会更改...它应该向我显示没有该用户的相同表单。
我尝试了很多东西,但我使用的是 Primefaces 3.0.M3 我的表单表是服务器创建的,因此它应该可以使用ajax。
有人知道出了什么问题吗?
谢谢 !
<h:form id="main" prependId="false">
<p:dataTable var="user" value="#{userController.allUsers}" id="userTable">
<p:ajax event="rowEdit" update="@this" listener="#{userController.onEditRow}" />
<f:facet name="header">
#{bundle.ListOfUsers}
</f:facet>
<p:column headerText="#{bundle.USERNAME}" style="width:110px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.name}" style="width:110%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="#{bundle.Login}" style="width:100px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.login}" />
</f:facet>
<f:facet name="input">
<h:outputText value="#{user.login}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="#{bundle.Roles}" style="width:180px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.rolesCollection}"/>
</f:facet>
<f:facet name="input">
<p:selectManyMenu value="#{user.rolesCollection}"
converter="rolesConverter"
style=" width:100%;">
<f:selectItems value="#{roleController.listOfRoles}"
var="roles"
itemLabel="#{roles.rolename}"
itemValue="#{roles}"
/>
</p:selectManyMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="#{bundle.edit}" style="width:10px; overflow:visible;">
<p:rowEditor/>
</p:column>
<p:column headerText="#{bundle.delete}" style="width:10px; overflow:visible;">
<p:commandButton update=":main" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete" >
<f:param value="#{user.id}" name="userAction" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:confirmDialog message="Are you sure? user:#{param['userAction']} " width="500"
header="Confirm" severity="alert" widgetVar="confirmation" >
<p:commandButton value="Yes sure" update="userTable" actionListener="#{userController.deleteAction( param['userAction'])}" oncomplete="confirmation.hide()" >
<f:param name="userAction" value="#{param['userAction']}" />
</p:commandButton>
<p:commandButton value="Not yet" onclick="confirmation.hide()" type="button" />
</p:confirmDialog>
</h:form>
这是控制器方法,
public void deleteAction(String id){
userFacade.remove(userFacade.find(Integer.parseInt(id)));
}
该方法正在被调用并且正在删除用户。
I have the page below, everything works fine...
Except that after I click the delete button and hit "Yes Sure" in the Confirm Dialog My page doesn't change... It should show me the same form without that user.
I tryed a lot of things, but I am using Primefaces 3.0.M3
My form table is server created so it should be ajax usable.
Anyone got an idea what is wrong ?
Thanks !
<h:form id="main" prependId="false">
<p:dataTable var="user" value="#{userController.allUsers}" id="userTable">
<p:ajax event="rowEdit" update="@this" listener="#{userController.onEditRow}" />
<f:facet name="header">
#{bundle.ListOfUsers}
</f:facet>
<p:column headerText="#{bundle.USERNAME}" style="width:110px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.name}" style="width:110%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="#{bundle.Login}" style="width:100px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.login}" />
</f:facet>
<f:facet name="input">
<h:outputText value="#{user.login}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="#{bundle.Roles}" style="width:180px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.rolesCollection}"/>
</f:facet>
<f:facet name="input">
<p:selectManyMenu value="#{user.rolesCollection}"
converter="rolesConverter"
style=" width:100%;">
<f:selectItems value="#{roleController.listOfRoles}"
var="roles"
itemLabel="#{roles.rolename}"
itemValue="#{roles}"
/>
</p:selectManyMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="#{bundle.edit}" style="width:10px; overflow:visible;">
<p:rowEditor/>
</p:column>
<p:column headerText="#{bundle.delete}" style="width:10px; overflow:visible;">
<p:commandButton update=":main" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete" >
<f:param value="#{user.id}" name="userAction" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:confirmDialog message="Are you sure? user:#{param['userAction']} " width="500"
header="Confirm" severity="alert" widgetVar="confirmation" >
<p:commandButton value="Yes sure" update="userTable" actionListener="#{userController.deleteAction( param['userAction'])}" oncomplete="confirmation.hide()" >
<f:param name="userAction" value="#{param['userAction']}" />
</p:commandButton>
<p:commandButton value="Not yet" onclick="confirmation.hide()" type="button" />
</p:confirmDialog>
</h:form>
Here is the controller method
public void deleteAction(String id){
userFacade.remove(userFacade.find(Integer.parseInt(id)));
}
This method is being called and it's deleting the user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除用户后,您需要在 bean 的操作方法中重新加载
allUsers
列表。否则,JSF 将只检索原始列表。显然,您正在视图作用域 bean 的(后)构造函数中预先填充列表,这就是 F5 起作用的原因。
You need to reload the
allUsers
list in the bean's action method after deleting the user.Otherwise JSF will just retrieve the original list. You're apparently prepopulating the list in the (post)constructor of a view scoped bean, that's why a F5 works.