Jsf 嵌套用户界面:包含和保留用户界面:参数问题
我无法在ui:param传递的嵌套ui:include中保留值 那么说,, page1.xhtml包含Jsf 嵌套用户界面:包含和保留用户界面:参数问题,jsf,primefaces,jsf-2.2,Jsf,Primefaces,Jsf 2.2,我无法在ui:param传递的嵌套ui:include中保留值 那么说,, page1.xhtml包含 <?xml version="1.0" encoding="UTF-8"?> <ui:composition template="../template.xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.s
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="../template.xhtml" xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<ui:param name="paramGlobal" value="123" />
<ui:define name="content">
<h:form id="frm1">
<f:view>
<ui:include src="page2.xhtml">
<ui:param name="paramInclude" value="abc"></ui:param>
</ui:include>
</f:view>
</h:form>
</ui:define>
</ui:composition>
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<p:panelGrid columns="2">
<p:outputLabel value="Page 2"></p:outputLabel>
<p:outputLabel value="Value"></p:outputLabel>
<p:outputLabel value="Global"></p:outputLabel>
<p:inputText value="#{paramGlobal}"></p:inputText>
<p:outputLabel value="Param Include"></p:outputLabel>
<p:inputText value="#{paramInclude}"></p:inputText>
<ui:include src="page3.xhtml">
<ui:param name="paramNestedInclude" value="def"></ui:param>
</ui:include>
</p:panelGrid>
</ui:composition>
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<p:outputLabel value="Page 3"></p:outputLabel>
<p:outputLabel value="Value"></p:outputLabel>
<p:outputLabel value="Global"></p:outputLabel>
<p:inputText value="#{paramGlobal}"></p:inputText>
<p:outputLabel value="Param Include"></p:outputLabel>
<p:inputText value="#{paramInclude}"></p:inputText>
<p:outputLabel value="Param Nested Include"></p:outputLabel>
<p:inputText value="#{paramNestedInclude}"></p:inputText>
</ui:composition>
而page2.xhtml包含
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="../template.xhtml" xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<ui:param name="paramGlobal" value="123" />
<ui:define name="content">
<h:form id="frm1">
<f:view>
<ui:include src="page2.xhtml">
<ui:param name="paramInclude" value="abc"></ui:param>
</ui:include>
</f:view>
</h:form>
</ui:define>
</ui:composition>
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<p:panelGrid columns="2">
<p:outputLabel value="Page 2"></p:outputLabel>
<p:outputLabel value="Value"></p:outputLabel>
<p:outputLabel value="Global"></p:outputLabel>
<p:inputText value="#{paramGlobal}"></p:inputText>
<p:outputLabel value="Param Include"></p:outputLabel>
<p:inputText value="#{paramInclude}"></p:inputText>
<ui:include src="page3.xhtml">
<ui:param name="paramNestedInclude" value="def"></ui:param>
</ui:include>
</p:panelGrid>
</ui:composition>
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<p:outputLabel value="Page 3"></p:outputLabel>
<p:outputLabel value="Value"></p:outputLabel>
<p:outputLabel value="Global"></p:outputLabel>
<p:inputText value="#{paramGlobal}"></p:inputText>
<p:outputLabel value="Param Include"></p:outputLabel>
<p:inputText value="#{paramInclude}"></p:inputText>
<p:outputLabel value="Param Nested Include"></p:outputLabel>
<p:inputText value="#{paramNestedInclude}"></p:inputText>
</ui:composition>
最后,page3.xhtml包含
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="../template.xhtml" xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<ui:param name="paramGlobal" value="123" />
<ui:define name="content">
<h:form id="frm1">
<f:view>
<ui:include src="page2.xhtml">
<ui:param name="paramInclude" value="abc"></ui:param>
</ui:include>
</f:view>
</h:form>
</ui:define>
</ui:composition>
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<p:panelGrid columns="2">
<p:outputLabel value="Page 2"></p:outputLabel>
<p:outputLabel value="Value"></p:outputLabel>
<p:outputLabel value="Global"></p:outputLabel>
<p:inputText value="#{paramGlobal}"></p:inputText>
<p:outputLabel value="Param Include"></p:outputLabel>
<p:inputText value="#{paramInclude}"></p:inputText>
<ui:include src="page3.xhtml">
<ui:param name="paramNestedInclude" value="def"></ui:param>
</ui:include>
</p:panelGrid>
</ui:composition>
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<p:outputLabel value="Page 3"></p:outputLabel>
<p:outputLabel value="Value"></p:outputLabel>
<p:outputLabel value="Global"></p:outputLabel>
<p:inputText value="#{paramGlobal}"></p:inputText>
<p:outputLabel value="Param Include"></p:outputLabel>
<p:inputText value="#{paramInclude}"></p:inputText>
<p:outputLabel value="Param Nested Include"></p:outputLabel>
<p:inputText value="#{paramNestedInclude}"></p:inputText>
</ui:composition>
我得到的输出如下:
第2页价值
全局:[空白]
参数包括:abc
第3页:价值
全局:[空白]
参数包括:[空白]
参数嵌套包括:def
我不知道为什么ui:param没有在包含的页面中传递。发现了这个问题
MyFacesJSF2.2采用了ui:param
、ui:include
和ui:composition
的工作方式
在web.xml
<context-param>
<param-name>org.apache.myfaces.STRICT_JSF_2_FACELETS_COMPATIBILITY</param-name>
<param-value>true</param-value>
</context-param>
org.apache.myfaces.STRICT_JSF_2_FACELETS_兼容性
真的
这将使这些组件的行为与前面相同