Primefaces p:在动态页面中未调用commandButton操作

Primefaces p:在动态页面中未调用commandButton操作,primefaces,actionlistener,commandbutton,Primefaces,Actionlistener,Commandbutton,我有一个应用程序,它的布局有左布局和中布局单元(demoLayout.xhtml)。在主页(main.xhtml)上,我在左侧布局单元(demoree.xhtml)上有p:tree,在中央布局单元上有三种不同的形式(first.xhtml、second.xhtml、third.xhtml)。使用树节点单击来进行中心表单切换。我的默认中心表单是first.xhtml,当我没有在first.xhtml上放置p:commandButton时,在second.xhtml和third.xhtml上的命令按

我有一个应用程序,它的布局有左布局和中布局单元(demoLayout.xhtml)。在主页(main.xhtml)上,我在左侧布局单元(demoree.xhtml)上有p:tree,在中央布局单元上有三种不同的形式(first.xhtml、second.xhtml、third.xhtml)。使用树节点单击来进行中心表单切换。我的默认中心表单是first.xhtml,当我没有在first.xhtml上放置p:commandButton时,在second.xhtml和third.xhtml上的命令按钮没有被调用。当我将p:commandButton放在first.xhtml上时,其他命令按钮可以工作,但我不想将p:commandButton放在first.xhtml上。我该怎么办

demoLayout.xhtml


#{title}
默认西部内容
默认中心内容
main.xhtml


demoree.xhtml


加载
first.xhtml





second.xhtml





third.xhtml





Demo3MBean.java

@ManagedBean(name=“demo3MBean”)
@视域
公共类Demo3MBean扩展TlosSWBaseBean实现可序列化{
私有静态最终长serialVersionUID=-5045378111128309503L;
私有字符串activePanel=第一个\u面板;
公共最终静态字符串FIRST\u PANEL=“FIRST.xhtml”;
公共最终静态字符串SECOND\u PANEL=“SECOND.xhtml”;
公共最终静态字符串THIRD_PANEL=“THIRD.xhtml”;
nodeselect上的公共无效(NodeSelectEvent事件){
String nodeType=event.getTreeNode().getType();
if(nodeType.equals(“First”)){
activePanel=第一个面板;
}else if(nodeType.equals(“Second”)){
activePanel=第二个_面板;
}else if(nodeType.equals(“Third”)){
activePanel=第三个面板;
}
}
公共无效打印ME1(ActionEvent e){
System.out.println(“Me 1”);
}
公共无效打印ME2(ActionEvent e){
System.out.println(“Me 2”);
}
公共无效打印ME3(ActionEvent e){
System.out.println(“Me 3”);
}
公共字符串getActivePanel(){
返回活动面板;
}
公共void setActivePanel(字符串activePanel){
this.activePanel=activePanel;
}
}
demoreebean.java

@ManagedBean(name=“demoreebean”)
公共类bean{
独活根;
@抑制警告(“未使用”)
公共bean(){
root=新的DefaultTreeNode(“root”,null);
TreeNode0=新的默认TreeNode(“第一个”、“第一个节点”、根节点);
TreeNode1=新的默认TreeNode(“第二个”、“第二个节点”、根节点);
TreeNode2=新的默认TreeNode(“第三”、“第三节点”、根节点);
}
公共树节点getRoot(){
返回根;
}
}
我也读了这些:


main.xhtml中的此部分是问题的原因

<ui:define name="center">
    <ui:include src="#{demo3MBean.activePanel}" />
</ui:define>

您将看到按钮起作用。

通过更新包含文件的内部表单来包含不同的文件是不可能的。由于每个文件中都有表单
rightForm
,因此仅在选择树节点时更新当前加载文件的
rightForm
。因此,将永远不会加载不同的文件。
此外,当每个文件中都存在相同的表单时,在每个文件中定义相同的表单是一种糟糕的方法(类似于
咆哮

要解决此问题,请删除
first.xhtml
second.xhtml
third.xhtml
中的
h:form
,并将
main.xhtml
中的第二个
ui:define
更改为以下内容:

<ui:define name="center">
    <h:form id="rightForm">
        <ui:include src="#{demo3MBean.activePanel}" />
    </h:form>
</ui:define>

在运行时更改src的值将不起作用

<ui:define name="center">
    <ui:include src="#{demo3MBean.activePanel}" />
</ui:define>

解决问题的另一种解决方案是对xhtml页面使用呈现标志

<ui:define name="center">

<s:div rendered="#{demo3MBean.firstFlag}">
    <ui:include src="first.xhtml" />
</s:div>

<s:div rendered="#{demo3MBean.secondFlag}">
    <ui:include src="second.xhtml" />
</s:div>

<s:div rendered="#{demo3MBean.thirdFlag}">
    <ui:include src="third.xhtml.xhtml" />
</s:div>

</ui:define>

初始将“所有页面”标志设置为FALSE。仅当单击相关树节点时,才将特定标志值设置为TRUE。不要忘记设置包含页面的所有组件的唯一“id”

使用上述解决方案,组件(如commandButtons、commandLinks等)的action和actionListener等属性也将正常且完美地工作

希望这能解决你的问题。
如果有帮助的话,也别忘了接受我的回答。祝你今天愉快

谢谢回复,但我不能使用静态页面值。我想在运行时更改center xhtml。谢谢,但在问我的问题之前,我也尝试了你的建议,但没有成功。我把所有的代码都放进去了,如果你想试试的话。
<ui:define name="center">
    <ui:include src="#{demo3MBean.activePanel}" />
</ui:define>
<ui:define name="center">

<s:div rendered="#{demo3MBean.firstFlag}">
    <ui:include src="first.xhtml" />
</s:div>

<s:div rendered="#{demo3MBean.secondFlag}">
    <ui:include src="second.xhtml" />
</s:div>

<s:div rendered="#{demo3MBean.thirdFlag}">
    <ui:include src="third.xhtml.xhtml" />
</s:div>

</ui:define>