Jsf 对话框内的按钮:对话框未调用控制器方法
我遇到了标题中描述的问题 问题的小说明如下所示: 我有一个用来打开对话框的按钮。然后,在该对话框中,有一个按钮可以在第一个对话框的顶部打开另一个对话框。单击第二个按钮后,我希望调用控制器中的方法,但什么也没发生。h:outputText中的值读取正确,所以我想连接控制器->视图没有问题 我正在使用:Jsf 对话框内的按钮:对话框未调用控制器方法,jsf,jsf-2,primefaces,controller,dialog,Jsf,Jsf 2,Primefaces,Controller,Dialog,我遇到了标题中描述的问题 问题的小说明如下所示: 我有一个用来打开对话框的按钮。然后,在该对话框中,有一个按钮可以在第一个对话框的顶部打开另一个对话框。单击第二个按钮后,我希望调用控制器中的方法,但什么也没发生。h:outputText中的值读取正确,所以我想连接控制器->视图没有问题 我正在使用: SpringWeb3.1.2.1版本 JSF2.2.10 Primefaces 5.1 代码: beans.xml <bean id="testController" class="tes
- SpringWeb3.1.2.1版本
- JSF2.2.10
- Primefaces 5.1
<bean id="testController" class="test.TestController" />
test.xhtml
<h:panelGrid columns="1" cellpadding="5">
<p:commandButton value="Basic" type="button" onclick="PF('dlg1').show();" />
</h:panelGrid>
<p:dialog widgetVar="dlg1">
<h:outputText value="Resistance to PrimeFaces is futile!" />
<h:panelGrid columns="1" cellpadding="5">
<p:commandButton value="Basic" type="button" onclick="PF('dlg2').show();" />
</h:panelGrid>
<p:dialog widgetVar="dlg2">
<h:outputText value="#{testController.test}" />
<p:commandButton value="Call method" type="button" actionListener="#{testController.testMethod}" />
</p:dialog>
</p:dialog>
我尝试的是:
- 向每个p:对话框添加appendToBody=“true”
- 从p:commandButton更改为p:button
- 从actionListener更改为action
组件。这没有道理。把它们分开
必须有自己的
,特别是当您显式使用appendToBody=“true”
或appendTo=“@(body)”
时,否则无法提交任何内容,因为JavaScript会将对话框从其在HTML DOM树中的位置重新定位到body的末尾,使它不再以某种形式存在
充当“单击”按钮,而不是提交按钮。从提交按钮中删除该属性<h:form>
<h:panelGrid columns="1" cellpadding="5">
<p:commandButton value="Basic" type="button" onclick="PF('dlg1').show();" />
</h:panelGrid>
</h:form>
<p:dialog widgetVar="dlg1">
<h:form>
<h:outputText value="Resistance to PrimeFaces is futile!" />
<h:panelGrid columns="1" cellpadding="5">
<p:commandButton value="Basic" type="button" onclick="PF('dlg2').show();" />
</h:panelGrid>
</h:form>
</p:dialog>
<p:dialog widgetVar="dlg2">
<h:form>
<h:outputText value="#{testController.test}" />
<p:commandButton value="Call method" actionListener="#{testController.testMethod}" />
</h:form>
</p:dialog>
好的。我想我找到了解决这个问题的方法 问题似乎是:
type="button"
我从每个按钮的属性列表中删除了它,现在它甚至可以在没有h:form的情况下工作。谢谢您的帮助。2只有在使用了
appendToBody=true
或appendTo=@(body)
时才会发生。尽管我刚刚在BalusC复制了您的代码,但它仍然不起作用。那些嵌套对话框是我的错误。很多次尝试中的一次终于成功了,但我忘了改变它。从dialog中打开dialog并能够调用第二个对话框中的一些操作对我来说非常重要。
type="button"