Question

j'attache à créer mon propre mécanisme de modèle pour un site. Je l'ai fait 2 balises personnalisées nommées « TemplateInsert » et « TemplateFor » on les utiliser comme ceci:

<prefix:insert templateFile="someFile>
    <prefix:for name="body">
        some content here
    </prefix:for>

    other prefix:for tags...

</prefix:insert>

cela fonctionne parfaitement à moins que des balises JSF dans votre « contenu ». Le serveur ne semble pas les analyser. Est-ce que quelqu'un sait comment je peux résoudre ce problème?

cheers!

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top