X. *_*uff 1 jsf dialog controller primefaces jsf-2
我遇到了标题中所述的问题。
问题的简短描述如下:我有一个用于打开对话框的按钮。然后,在该对话框中,有一个按钮可在第一个对话框的顶部打开另一个对话框。单击第二个按钮后,我希望调用控制器中的方法,但没有任何反应。h:outputText中的值已正确读取,因此我猜它与连接控制器->视图无关。
我正在使用:
码:
beans.xml
<bean id="testController" class="test.TestController" />
Run Code Online (Sandbox Code Playgroud)
TestController.java
public class TestController implements Serializable
{
private static final long serialVersionUID = 7028608421091861830L;
private String test;
public TestController()
{
test = "abc";
}
public void testMethod()
{
test = "cba";
}
public String getTest()
{
return test;
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我试过的
但没有任何帮助。
对于不调用给定方法的原因有何帮助或建议,我将不胜感激。
有3个问题。
您正在嵌套<p:dialog>
组件。这没有道理。分开他们。
一个<p:dialog>
必须有自己的<h:form>
,特别是当你明确地使用appendToBody="true"
或appendTo="@(body)"
,否则没有什么可以提交,因为JavaScript将重新定位的对话框了其在HTML DOM树中的位置,以身体的末端,使其不被坐在形式了。
A <p:commandButton type="button">
充当“单击”按钮,而不充当提交按钮。从提交按钮中删除该属性。
总而言之,这应该是这样的:
<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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4260 次 |
最近记录: |