سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top