jsf - p:commandButton doesn't dislpay p:dialog
问题描述
i have a problem with the display of a dialog on a click. It's a obvious one but i can't spot the bug. I've been stuck on this for days, it's crazy. Can you help me please.
<h:form id="form">
<p:commandButton
rendered="#{characterBean.characterSession.characterName ne null}"
value="#{characterBean.characterSession.title.titleName}"
icon="fa fa-fw fa-edit" onclick="PF('dlg').show();"
update="@form"/>
<p:dialog id="titleDetail" header="#{i18n['title.yourTitles']}"
widgetVar="dlg" dynamic="true" closable="false" resizable="false"
showEffect="fade" hideEffect="fade">
<h:panelGroup>
<p:messages autoUpdate="true" />
<h:selectOneMenu id="titleSelect" converter="#{titleConverter}"
value="#{characterBean.characterSession.title}">
<f:selectItems value="#{characterBean.titleUnlocked}" var="t"
itemValue="#{t}" itemLabel="#{t.titleName}" />
</h:selectOneMenu>
<hr />
<h:panelGrid columns="2" style="width: 100%; text-align:center">
<p:commandButton value="#{i18n['general.submit']}"
icon="fa fa-check"
actionListener="#{characterBean.updateCharacterTitle}"
oncomplete="PF('dlg').hide();" update="@form" />
<p:commandButton value="#{i18n['general.cancel']}"
icon="fa fa-close" action="#{characterBean.submitCancel}"
oncomplete="PF('dlg').hide();" update="@form" process="@this" />
</h:panelGrid>
<p:remoteCommand name="updateForm()" process="@this" update="@form" />
</h:panelGroup>
</p:dialog>
</h:form>
解决方案
核心问题本质上是这样的:
<h:form>
<p:commandButton onclick="PF('dlg').show();" update="@form"/>
<p:dialog widgetVar="dlg">
...
</p:dialog>
</h:form>
- 的默认状态
<p:dialog>
为隐藏。 - 显示
onclick
对话框。 update
更新<h:form>
. _<p:dialog>
也包含在更新中。- 所以,
<p:dialog>
又被隐藏了。
有几种解决方案:
不要让
update
包括<p:dialog>
.<h:form> <h:panelGroup id="outsideDialog"> <p:commandButton onclick="PF('dlg').show();" update="outsideDialog"/> </h:panelGroup> <p:dialog widgetVar="dlg"> ... </p:dialog> </h:form>
替换
onclick
为,因为oncomplete
它在update
.<h:form> <p:commandButton update="@form" oncomplete="PF('dlg').show();" /> <p:dialog widgetVar="dlg"> ... </p:dialog> </h:form>
移到
<p:dialog>
外面<h:form>
并给它自己的<h:form>
。<h:form> <p:commandButton update="@form :dlg" oncomplete="PF('dlg').show();" /> </h:form> <p:dialog id="dlg" widgetVar="dlg"> <h:form> ... </h:form> </p:dialog>
或者,取决于您是否真的需要更新对话框的内容
<h:form> <p:commandButton onclick="PF('dlg').show();" update="@form" /> </h:form> <p:dialog widgetVar="dlg"> <h:form> ... </h:form> </p:dialog>
推荐的解决方案是 3。
也可以看看:
推荐阅读
- javascript - 内容可编辑的正则表达式空格不起作用
- c# - 如何从 azure 函数执行我的 docker 容器
- c - 使用字节数组我得到一个“从 char* 到字节的无效转换”
- java - 没有使用 JUnit @Rule 删除 TemporaryFolder
- html - 通过 CSS 替换图像
- jquery - 如何用 jquery html(String) 替换 .innerHTML(String)?
- jenkins - 在 GitHub 拉取请求页面上添加一个按钮以手动触发 Jenkins 作业
- python - 使用 pymongo 从集合中获取 Mongo 字段名称
- python - 关于网页抓取的问题 - 与 Discord
- python - 向 Kivy.app.on_start 函数发送参数