Primefaces Ajax 操作未触发更新

发布于 2024-12-09 22:56:46 字数 5169 浏览 0 评论 0原文

我有下面的页面,一切正常...

除了在我单击删除按钮并在确认对话框中点击“是的”之后,我的页面不会更改...它应该向我显示没有该用户的相同表单。

我尝试了很多东西,但我使用的是 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 技术交流群。

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

发布评论

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

评论(1

暮年 2024-12-16 22:56:46

删除用户后,您需要在 bean 的操作方法中重新加载 allUsers 列表。

public void deleteAction(String userId) {
    userService.delete(Long.valueOf(userId));
    allUsers = userService.list();
}

否则,JSF 将只检索原始列表。显然,您正在视图作用域 bean 的(后)构造函数中预先填充列表,这就是 F5 起作用的原因。

You need to reload the allUsers list in the bean's action method after deleting the user.

public void deleteAction(String userId) {
    userService.delete(Long.valueOf(userId));
    allUsers = userService.list();
}

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.

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