java - JSF2 - 使用 p :dialog reload and closes once a function is called 弹出表

标签 java primefaces xhtml

我是 JSF2 新手。 我正在尝试使用 p:dialog 显示表格。 该表有项目列表,并且在行末尾有删除功能。我的问题是,当它单击删除时,整个页面都会重新加载,并且我的弹出表格会关闭。 然而,当它不在p:dialog 中时,删除功能可以正常工作。 我的 bean,无论是 View 范围还是 session 范围,都会产生相同的输出。

这是我的 bean 中的删除代码

public String delete(Items items) {

    getItemList.remove(items);
    return null;
}

剪切我的 xhtml,

<p:dialog header="Item Table" widgetVar="popUpTbl" modal="true" >
        <h:form>
            <p:dataTable style="width:800px;height:485px;" id="popUpTbl" var="item" value="#{myBean.itemList}" >
                <p:column headerText="Item A">
                    <h:outputText value="#{item.itemA}" />
                </p:column>
                <p:column headerText="Item B">
                    <h:outputText value="#{item.itemB}" />                        
                </p:column>
                <p:column headerText="Action">
                    <h:commandLink value="Delete" action="#{myBean.delete(item)}" />
                </p:column>
            </p:dataTable>                
        </h:form>
    </p:dialog>

最佳答案

添加 ID <h:form><p:dialog>并通过提供完全限定名称来更新表单,在本例中只是 :dialogId:formId并从 <h:commandLink> 更新它还有一件事我注意到你的对话框 widgetVar 和数据表的 id 是相同的,这是错误的,我在下面的示例中更正了

 <p:dialog id="dialogId" header="Item Table" widgetVar="dialogIdWidget" modal="true" >
     <h:form id=formId>
        <p:dataTable style="width:800px;height:485px;" id="popUpTbl" 
            var="item" value="#{myBean.itemList}" >
                    .
                    .
                    .
                    <p:column headerText="Action">
                        <h:commandLink value="Delete" action="#{myBean.delete(item)}" update=":dialogId:formId" />
                    </p:column>
                </p:dataTable>                
            </h:form>
        </p:dialog>

关于java - JSF2 - 使用 p :dialog reload and closes once a function is called 弹出表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36995462/

相关文章:

java - 如何用 url 的单斜杠替换双斜杠

jsf-2 - 复选框数据表 primefaces 不起作用

html - CSS namespace 属性选择器是否适用于 XHTML/HTML 元素?

javascript - IE8 : checkbox onclick not called when setting class to that

java - Wicket DropDownChoice 不能与 PropertyModels 一起正常工作

java - JNI 代码中的内存泄漏

java - 将一串数字拆分为单独的数字

javascript - 使用 widgetVar,如何禁用或启用 PrimeFaces selectOneButton

java - PrimeFaces 3.0 : How to change tab focus with `<p:tabView>`

php - 无法使用php中的xquery从xhtml获取带有xpath的两个子元素来操作