Spring web应用程序JSF素面
我正在开发基于java的web应用程序,我正在使用jsf 2.2和prime faces, 我面临着这个问题:我有两个按钮,第一个是删除,另一个是编辑,删除按钮打开一个确认对话框,还有两个按钮是/否,编辑按钮打开一个编辑对话框,我的问题是,当我在确认对话框中单击yes按钮时,它不起作用,但当我从代码中删除edit对话框并重新启动程序时,yes按钮工作正常。 我希望找到一个解决方案,可以帮助我在代码中保持编辑对话框,并使“是”按钮正常工作 页面代码示例:Spring web应用程序JSF素面,spring,jsf,primefaces,Spring,Jsf,Primefaces,我正在开发基于java的web应用程序,我正在使用jsf 2.2和prime faces, 我面临着这个问题:我有两个按钮,第一个是删除,另一个是编辑,删除按钮打开一个确认对话框,还有两个按钮是/否,编辑按钮打开一个编辑对话框,我的问题是,当我在确认对话框中单击yes按钮时,它不起作用,但当我从代码中删除edit对话框并重新启动程序时,yes按钮工作正常。 我希望找到一个解决方案,可以帮助我在代码中保持编辑对话框,并使“是”按钮正常工作 页面代码示例: <ui:composition x
<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>
在将代码简化一点并亲自尝试之后,我可能已经找到了导致问题的原因。 首先,我的行为和你描述的一样。然后我修改了这两行:删除末尾的括号 actionListener={myController.OnDeleteClicked} 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>
希望这有帮助 请将您的标题更改为具体问题,这要求您创建一个。可能的重复。如果这是原因,则在进行更改之前,在我的示例中按下按钮时应该有错误,按下按钮时有错误。我认为提问者没有具体说明这个细节,或者没有这个问题
<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>