Templates 使用ui:include with div而不是composition
通常,我使用balus制作的模板如下所示: 但至少我看到了一个朋友的例子,他用了一个div。比如:Templates 使用ui:include with div而不是composition,templates,jsf-2,facelets,xml-namespaces,uiinclude,Templates,Jsf 2,Facelets,Xml Namespaces,Uiinclude,通常,我使用balus制作的模板如下所示: 但至少我看到了一个朋友的例子,他用了一个div。比如: <?xml version="1.0" encoding="UTF-8"?> <html 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.c
<?xml version="1.0" encoding="UTF-8"?>
<html 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"
>
<h:head></h:head>
<h:body>
<h:form acceptcharset="ISO-8859-1">
<ui:include src="test2.xhtml"/>
</h:form>
</h:body>
</html>
插入:
<div 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">
<h:outputText value="HELLO WORLD"/>
</div>
它也起作用。但我认为这是一个错误的使用,不是吗?
感谢您的时间和回答。它们是不同的做事方式。在这里,您只是将一个视图包含到另一个视图中。这意味着您仍然需要复制父级或使用条件将其用作模板。通过模板化,您可以解决这个问题,只需编写一个主模板来扩展所有视图。我觉得干净多了。但这两种解决方案都有效吗?With div是一个警告,因为它没有属性xmlns,但有效,两者都有效。您也可以在Facelet中使用普通HTML。