gpt4 book ai didi

primefaces - p :commandButton action has not being called in dynamic pages

转载 作者:行者123 更新时间:2023-12-02 01:59:22 25 4
gpt4 key购买 nike

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

demoLayout.xhtml

    <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<f:view id="mainPanel" encoding="UTF-8" contentType="text/html">

<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="EmulateIE8" />
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
<title>#{title}</title>
</f:facet>

</h:head>

<h:body>

<p:layout fullPage="true">

<p:layoutUnit id="left" position="west" size="300" resizable="true" closable="true" collapsible="true" header="Quick Links" visible="true" minSize="200">
<div id="west">
<ui:insert name="west">
Default West Content
</ui:insert>
</div>
</p:layoutUnit>

<p:layoutUnit id="center" position="center">
<div id="centerDiv">
<ui:insert name="center">
Default Center Content
</ui:insert>
</div>
</p:layoutUnit>

</p:layout>

</h:body>
</f:view>

</html>

ma​​in.xhtml

<ui:composition template="demoLayout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<ui:param name="title" value="demo" />

<ui:define name="west">
<ui:include src="demoTree.xhtml" />
</ui:define>

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

</ui:composition>

demoTree.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<h:form id="treeForm">

<p:growl id="messages" showDetail="true" sticky="false" />

<p:tree value="#{demoTreeBean.root}" var="node" id="tree" animate="true" style="width:350px;height:720px" dynamic="true" cache="false"
selectionMode="single">

<p:treeNode type="First">
<h:outputText value="#{node}" id="lblNode1" />
</p:treeNode>
<p:treeNode type="Second">
<h:outputText value="#{node}" id="lblNode2" />
</p:treeNode>
<p:treeNode type="Third">
<h:outputText value="#{node}" id="lblNode3" />
</p:treeNode>
<p:ajax event="select" update=":rightForm" listener="#{demo3MBean.onNodeSelect}" />
</p:tree>

<p:blockUI block=":center" trigger="tree">
LOADING<br />
<p:graphicImage value="/images/ajax-loader.gif" />
</p:blockUI>

</h:form>

</ui:composition>

first.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<h:form id="rightForm">

<p:growl id="messages" showDetail="true" sticky="false" />

<br></br>

<p:fieldset id="resourceList" legend="1 nolu grup">

<h:outputText value="1 Nolu XHTML" />
<br />
<ui:remove>
<p:commandButton id="buton" value="Print Me 1" actionListener="#{demo3MBean.printMe1}" />
</ui:remove>
</p:fieldset>

</h:form>

</ui:composition>

second.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<h:form id="rightForm">

<p:growl id="messages" showDetail="true" sticky="false" />

<br></br>

<p:fieldset id="resourceList" legend="2 nolu grup">

<h:outputText value="2 Nolu XHTML" />
<br />
<p:commandButton id="buton" value="Print Me 2" actionListener="#{demo3MBean.printMe2}" />

</p:fieldset>

</h:form>

</ui:composition>

third.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<h:form id="rightForm">

<p:growl id="messages" showDetail="true" sticky="false" />

<br></br>

<p:fieldset id="resourceList" legend="3 nolu grup">

<h:outputText value="3 Nolu XHTML" />
<br />
<p:commandButton id="buton" value="Print Me 3" actionListener="#{demo3MBean.printMe3}" />

</p:fieldset>

</h:form>

</ui:composition>

Demo3MBean.java

@ManagedBean(name = "demo3MBean")
@ViewScoped
public class Demo3MBean extends TlosSWBaseBean implements Serializable {

private static final long serialVersionUID = -504537811128309503L;

private String activePanel = FIRST_PANEL;

public final static String FIRST_PANEL = "first.xhtml";
public final static String SECOND_PANEL = "second.xhtml";
public final static String THIRD_PANEL = "third.xhtml";

public void onNodeSelect(NodeSelectEvent event) {

String nodeType = event.getTreeNode().getType();
if (nodeType.equals("First")) {

activePanel = FIRST_PANEL;

} else if (nodeType.equals("Second")) {

activePanel = SECOND_PANEL;

} else if (nodeType.equals("Third")) {

activePanel = THIRD_PANEL;
}

}

public void printMe1(ActionEvent e) {
System.out.println("Me 1");
}

public void printMe2(ActionEvent e) {
System.out.println("Me 2");
}

public void printMe3(ActionEvent e) {
System.out.println("Me 3");
}

public String getActivePanel() {
return activePanel;
}

public void setActivePanel(String activePanel) {
this.activePanel = activePanel;
}

}

DemoTreeBean.java

@ManagedBean(name = "demoTreeBean")
public class DemoTreeBean {

private TreeNode root;

@SuppressWarnings("unused")
public DemoTreeBean() {
root = new DefaultTreeNode("Root", null);
TreeNode node0 = new DefaultTreeNode("First", "First Node", root);
TreeNode node1 = new DefaultTreeNode("Second", "Second Node", root);
TreeNode node2 = new DefaultTreeNode("Third", "Third Node", root);

}

public TreeNode getRoot() {
return root;
}
}

我也读过这些:

最佳答案

main.xhtml 中的这部分是导致问题的原因。

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

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

尝试使用像

这样的静态值
<ui:define name="center">
<ui:include src="third.xhtml" />
</ui:define>

你会看到按钮起作用了。

关于primefaces - p :commandButton action has not being called in dynamic pages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18020459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com