我正在尝试在PrimeFaces中进行轮询。为什么轮询列表器在<ui:composition template="/pages/layout.xhtml">
下调用时没有得到呼叫,而直接调用时却起作用。
这里是例子
我尝试使用<ui:composition template="/pages/layout.xhtml">
进行轮询,但不进行轮询。如果没有<ui:composition template="/pages/layout.xhtml">
的轮询,但是却没有<ui:composition template="/pages/layout.xhtml">
的轮询。
layout.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html" locale="en" encoding="UTF-8">
<h:head>
<title><ui:insert name="pageTitle">SampleApp</ui:insert></title>
<f:facet name="first">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
</f:facet>
<link
href="${facesContext.externalContext.requestContextPath}/resources/css/styles.css"
rel="stylesheet" type="text/css" />
<link
href="${facesContext.externalContext.requestContextPath}/resources/css/ReportStyle.css"
rel="stylesheet" type="text/css" />
</h:head>
<h:body>
<h:form id="form" prependId="false" enctype="multipart/form-data">
<p:layout id="layout" fullPage="true">
<p:layoutUnit position="north" size="50" resizable="false"
closable="false" collapsible="false"
style="overflow-x:hidden;overflow-y:hidden">
<table>
<tr valign="top">
<td width='100%'><h:outputText
style="font-weight: bold;font-size: 12px;" immediate="true "
value="SampleApp" /></td>
<td><h:outputLink style="font-weight: bold;"
immediate="true"
value="${facesContext.externalContext.requestContextPath}/pages/about.xhtml">About</h:outputLink>
<h:outputLink style="font-weight: bold;padding-left:10px"
immediate="true"
value="${facesContext.externalContext.requestContextPath}/pages/contactus.xhtml">Contact</h:outputLink>
</td>
</tr>
<tr>
<td><h:outputText style="font-weight: bold;font-size: 10px;"
immediate="true " value="Welcome, #{loginBean.emailid} " /></td>
</tr>
</table>
</p:layoutUnit>
<p:layoutUnit position="west" resizable="false" closable="false" collapsible="false" size="200">
<p:menu style="width:95%">
<p:submenu label="Reports">
<p:menuitem value="Dashboard" onclick="selectComponentLink(this)" url="/pages/Report/Dashboard.xhtml" />
</p:submenu>
</p:menu>
</p:layoutUnit>
<p:layoutUnit position="center">
<p:growl id="growl" life="2000" />
<ui:insert name="centerContent" />
</p:layoutUnit>
</p:layout>
</h:form>
</h:body>
</f:view>
</html>
Dashboard.xhtml-轮询不起作用
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
<ui:composition template="/pages/layout.xhtml">
<ui:define name="pageTitle">
<h:outputText value="Suites" />
</ui:define>
<ui:define name="centerContent">
<div class="bodycopy parbase">
<div style="clear: both"></div>
<div class="content-body">
<h:form id="test">
<h:panelGrid id="reportId1">
<h:outputText id="txt_count" value="#{executionBean.number}" />
<p:poll interval="3" listener="#{executionBean.increment}"
update="txt_count" />
</h:panelGrid>
</h:form>
</div>
<div style="clear: both"></div>
</div>
</ui:define>
</ui:composition>
</html>
Dashboard2.xhtml-轮询工作正常
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 contentType="text/html" locale="en" encoding="UTF-8">
<h:head>
<title><ui:insert name="pageTitle">SampleApp</ui:insert></title>
<f:facet name="first">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
</f:facet>
<link
href="${facesContext.externalContext.requestContextPath}/resources/css/styles.css"
rel="stylesheet" type="text/css" />
<link
href="${facesContext.externalContext.requestContextPath}/resources/css/ReportStyle.css"
rel="stylesheet" type="text/css" />
</h:head>
<h:body>
<h:form id="DashboardForm">
<h:outputText id="txt_count" value="#{executionBean.number}" />
<p:poll interval="3" listener="#{executionBean.increment}"
update="txt_count" />
</h:form>
</h:body>
</f:view>
</html>
ExecutionBean.java
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="executionBean")
@SessionScoped
public class ExecutionBean {
private int number;
public int getNumber() {
return number;
}
public void increment() {
System.out.println("number:" + number);
number++;
}
}
实际结果:当我在Dashboard2.xhtml中运行轮询时,它以未定义状态工作
然后
当我在Dashboard中运行轮询时,xhtml无法轮询,因为它已在
中定义答案 0 :(得分:1)
在您的“无效”示例中,您的ui:composition
定义了一个h:form
,该字符串最终位于<h:form id="form" prependId="false" enctype="multipart/form-data">
的{{1}}内部,而在第二个示例中,您有只有一个layout.xhtml
-nested forms are not allowed!