【问题标题】:web application J SF prime facesWeb 应用程序 JSF primefaces
【发布时间】:2018-04-05 13:44:22
【问题描述】:

我正在开发基于 web 的 java 应用程序,我正在使用 jsf 2.2 和 prime faces, 我面临这个问题:我有两个按钮,第一个是删除,另一个是编辑,删除按钮打开一个确认对话框,还有另外两个按钮是/否,编辑按钮打开一个编辑对话框,我的问题是当我单击确认对话框中的“是”按钮,它不起作用,但是当我从代码中删除编辑对话框并重新启动程序时,“是”按钮工作正常。 我希望找到一个解决方案,可以帮助我将编辑对话框保留在代码中并使“是”按钮正常工作。

页面代码示例:

 <ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:hftl="http://hftl.org"
xmlns:hf="http://xmlns.jcp.org/jsf/composite/tags"
template="../../templates/template.xhtml"
xmlns:e="http://primefaces.org/extension">

<ui:param name="pageTitle" value="#{messages['account.search']}" />




<ui:define name="content">


<h:form>

            <p:commandButton value="delete" onclick="PF('deletedlg').show()" 
                         id="delBtn" />


            <p:commandButton value="edit" onclick="PF('editDlg').show()"  id="edtBtn"/>

        <p:dataTable var="admin" value="#{adminBean.getLazyDataModel()}"
            paginator="true" rows="10"
            paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} 
     {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
            rowsPerPageTemplate="5,10,15" id="dataTable" lazy="true"
            binding="#{adminBean.dataTable}"
            selection="#{adminBean.selectedEntity}" selectionMode="single">


            <p:column headerText="id">
                <h:outputText value="#{admin.id}" id="xxxx" />
            </p:column>

            <p:column headerText="username">
                <h:outputText value="#{admin.username}" id="asdssasd" />
            </p:column>



        </p:dataTable>



        <p:dialog header="Notice" widgetVar="deletedlg" modal="true"
            showEffect="fade" hideEffect="fade" resizable="false" id="deletedlg">

                <p:outputPanel style="text-align:center;">



                    <h:outputText value="are you sure you want to delete" />

                    <p:commandButton value="Yes"
                        actionListener="#{adminBean.onDleteClicked()}"  id="yesBtn" />

                    <p:commandButton value="No" onclick="PF('deletedlg').hide()" id="noBtn" />

                </p:outputPanel>

        </p:dialog>

        <p:dialog header="Edit" widgetVar="editDlg" modal="true"
            showEffect="fade" hideEffect="fade" resizable="false" id="editDlg">
                <p:outputPanel style="text-align:center;">

                    <hf:textBox componentId="userNameTxt" label="username"
                        value="#{adminBean.entity.username}"
                        placeholder="enter user name here" />
                    <hf:textBox componentId="passwordTxt" label="passsword"
                        value="#{adminBean.entity.password}"
                        placeholder="enter password here" isPassword="true" />
                    <hf:textBox componentId="rPasswordTxt" label="passsword"
                        value="#{adminBean.rPassword}" placeholder="enter password here"
                        isPassword="true" />

                    <p:commandButton value="save"
                        actionListener="#{adminBean.onEditSaveClicked()}" id="saveBtn"/>

                </p:outputPanel>
        </p:dialog>

</ui:define>

【问题讨论】:

标签: spring jsf primefaces


【解决方案1】:

在稍微简化您的代码并亲自尝试之后,我可能已经找到了导致您的问题的原因。 首先,我的行为与您描述的相同。然后我修改了这两行:(去掉最后的括号)

actionListener="#{myController.onDleteClicked}"

actionListener="#{myController.onEditSaveClicked}"

这是我使用的完整示例:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:p="http://primefaces.org/ui">


    <h:form>
        <p:commandButton value="delete" onclick="PF('deletedlg').show()" id="delBtn" />
        <p:commandButton value="edit" onclick="PF('editDlg').show()" id="edtBtn"/>
        <p:column headerText="id">
            <h:outputText value="#{myForm.id}" id="xxxx" />
        </p:column>
        <p:column headerText="username">
            <h:outputText value="#{myForm.username}" id="asdssasd" />
        </p:column>

        <p:dialog header="Notice" widgetVar="deletedlg" modal="true"
                  showEffect="fade" hideEffect="fade" resizable="false" id="deletedlg">
            <p:outputPanel style="text-align:center;">
                <h:outputText value="are you sure you want to delete" />
                <p:commandButton value="Yes" actionListener="#{myController.onDleteClicked}"  id="yesBtn" />
                <p:commandButton value="No" onclick="PF('deletedlg').hide()" id="noBtn" />
            </p:outputPanel>
        </p:dialog>

        <p:dialog header="Edit" widgetVar="editDlg" modal="true"
                  showEffect="fade" hideEffect="fade" resizable="false" id="editDlg">
            <p:outputPanel style="text-align:center;">
                <p:commandButton value="save"
                                 actionListener="#{myController.onEditSaveClicked}" id="saveBtn"/>
            </p:outputPanel>
        </p:dialog>
    </h:form>
</ui:composition>

希望这会有所帮助!

【讨论】:

  • 如果是这个原因,按下按钮应该有错误
  • 在我的示例中(进行更改之前),按下按钮时出现错误。我不认为提问者指定了这个细节。
  • 或者没有这个问题
猜你喜欢
  • 2012-04-04
  • 2012-06-08
  • 1970-01-01
  • 2011-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-27
  • 2013-01-19
相关资源
最近更新 更多