我正在开发基于java网络的应用程序,我正在使用jsf 2.2和主要面孔, 我面临这个问题:我有两个按钮,第一个是删除,另一个是编辑,删除按钮打开一个确认对话框,有另外两个按钮是/否,编辑按钮打开编辑对话框,我的问题,当我单击确认对话框中的是按钮它不起作用,但当我从代码中删除编辑对话框并重新启动程序时,是按钮工作正常。 我希望找到一个解决方案,可以帮助我保持代码中的编辑对话框,并使yes按钮正常工作。
页面代码示例:
<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>
答案 0 :(得分: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>
希望这有帮助!