Java 带有JSF主体的JSP自定义标记
我打算为一个网站创建自己的模板机制。我制作了两个名为“TemplateInsert”和“TemplateFor”的自定义标记,其中一个使用它们的方式如下:Java 带有JSF主体的JSP自定义标记,java,jsp,jsf,tomcat,custom-tags,Java,Jsp,Jsf,Tomcat,Custom Tags,我打算为一个网站创建自己的模板机制。我制作了两个名为“TemplateInsert”和“TemplateFor”的自定义标记,其中一个使用它们的方式如下: <prefix:insert templateFile="someFile> <prefix:for name="body"> some content here </prefix:for> other prefix:for tags... </prefix
<prefix:insert templateFile="someFile>
<prefix:for name="body">
some content here
</prefix:for>
other prefix:for tags...
</prefix:insert>
这就是为什么jsf2.0/javaee6中Facelets成功使用JSP的众多原因之一。JSP提供的模板功能很少。但是,如果您按照各自的要求单独安装Facelets 1.x,则可以在JSF 1.x上使用Facelets 1.x
Facelets正好提供了您的功能需求。例如:
template.xhtml
<!DOCTYPE html>
<html lang="en"
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"
>
<head>
<title><ui:insert name="title" /></title>
</head>
<body>
<ui:insert name="body" />
</body>
</html>
<ui:composition template="template.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"
>
<ui:define name="title">Page title</ui:define>
<ui:define name="body">
<h:outputText value="JSF tags just work here." />
</ui:define>
</ui:composition>
我想说的是,把Facelets作为JSF视图技术,而不是重新发明一种基于JSP的技术。这就是为什么根据JSF 2.0/Java EE 6,Facelets已经成功使用JSP的众多原因之一。JSP提供的模板功能很少。但是,如果您按照各自的要求单独安装Facelets 1.x,则可以在JSF 1.x上使用Facelets 1.x
Facelets正好提供了您的功能需求。例如:
template.xhtml
<!DOCTYPE html>
<html lang="en"
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"
>
<head>
<title><ui:insert name="title" /></title>
</head>
<body>
<ui:insert name="body" />
</body>
</html>
<ui:composition template="template.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"
>
<ui:define name="title">Page title</ui:define>
<ui:define name="body">
<h:outputText value="JSF tags just work here." />
</ui:define>
</ui:composition>
我想说的是,将Facelets作为JSF视图技术,而不是基于JSP重新发明Facelets