xmlns:ui标记在JSPX页面中无法正确呈现

时间:2015-09-11 13:19:04

标签: jsp jsf jsf-2 facelets

我使用带有trinidad标记库的apache myfaces-2.0.23在eclipse中创建了一个新的JSF项目。我的Login.jspx如下所示,

<jsp:root xmlns="http://www.w3.org/1999/xhtml"
    xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" version="2.0"
    xmlns:tr="http://myfaces.apache.org/trinidad"
    xmlns:trh="http://myfaces.apache.org/trinidad/html"
    xmlns:c="http://java.sun.com/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
   <jsp:directive.page language="java"
        contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
    <jsp:text>
        <![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
    </jsp:text>
    <jsp:text>
        <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
    </jsp:text>
<ui:composition template="templates/templateLayout.jspx">
<f:view>
    <ui:define name="body">
        <tr:outputLabel value="User Name: "></tr:outputLabel>
        <tr:inputText required="true" value="#{login.userName}"></tr:inputText>
        <tr:spacer height="5"></tr:spacer>
        <tr:outputLabel value="Password: "></tr:outputLabel>
        <tr:inputText required="true" value="#{login.password}"></tr:inputText>
        <tr:spacer height="10"></tr:spacer>
        <tr:commandButton text="Login" action="#{loginAction.login}"></tr:commandButton>
    </ui:define>
</f:view>
</ui:composition>
</jsp:root>

当应用程序部署在JBoss中并运行时,我能够看到文本框和按钮。但是不显示templateLayout内容!

当我在浏览器中输入时,ui:composition标签只是按原样呈现。

<?xml version="1.0" encoding="ISO-8859-1" ?> 

         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    **<ui:composition** template="templates/templateLayout.jspx"><ui:define name="onPageLoadJavascript"/><ui:defin`enter code here`e name="pageSpecificJavascript"/><ui:define name="body">........................................................

这是如何引起的?如何解决?

1 个答案:

答案 0 :(得分:1)

您的错误在于您创建了一个旧的JSPX页面而不是现代的Facelets(XHTML)页面。 <ui:xxx>标记仅适用于Facelets(就像<jsp:xxx>标记仅在JSP(X)中有效)。此外,像PrimeFaces 2+和RichFaces 4+这样的JSF 2.x兼容组件库不再支持JSP(X),因为自JSF 2.0以来已经弃用了它。

您有2个选项:

  • 仅使用<jsp:xxx>标记。它只是不支持高级模板。
  • 使用Facelets(XHTML)代替JSP(X)。

由于自JSF 2.0以来不推荐使用JSP并且Facelets成功,因此第二个选项显然是首选。不要忘记摆脱所有<jsp:xxx>标签,否则你将面临同样的问题。

另见: