开发者

JSP Custom tag with JSF body

开发者 https://www.devze.com 2023-02-18 10:16 出处:网络
I\'m tying to create my own template mechanism for a site. I\'ve made 2 custom tags named \"TemplateInsert\" and \"TemplateFor\" one would use them like this:

I'm tying to create my own template mechanism for a site. I've made 2 custom tags named "TemplateInsert" and "TemplateFor" one would use them like this:

<开发者_运维问答prefix:insert templateFile="someFile>
    <prefix:for name="body">
        some content here
    </prefix:for>

    other prefix:for tags...

</prefix:insert>

this works perfectly unless there are JSF tags inside your "content". Server doesn't seem to parse them. Does anyone know how i can fix this?

cheers!


That's one of the plethora of reasons why JSP has been succeeded by Facelets as per JSF 2.0 / Java EE 6. JSP offers very little templating capabilities. You can however use Facelets 1.x on JSF 1.x if you install it separately as per their docbook.

Facelets offers exactly your functional requirement already out the box. An example:

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>

page.xhtml

<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>

I'd say, go for Facelets as JSF view technology instead of reinventing one based on JSP.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号