【问题标题】:<ui:insert> tag not working in facelets<ui:insert> 标签在 facelets 中不起作用
【发布时间】:2012-07-12 06:31:07
【问题描述】:

大家好,我遇到了一个非常奇怪的问题。我创建了一个客户端模板 facelet 和模板 facelet。但是当我运行我的网页时,它不会插入定义的标签。我的意思是不工作。这是我的代码
插入.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
   <title>facelet example </title>
</head>
<body> 
  <ui:insert name="face1"> </ui:insert>
  <ui:insert name="face2"> </ui:insert>
  <ui:insert name="face3"> </ui:insert>
  <ui:insert name="face4"> </ui:insert>
</body>
</html>

撰写.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html">
<body>
   <ui:composition template="insert.xhtml">
   <ui:define name="face1">
   <center><h2>Facelet</h2></center>
   <h3>Welcome to the Facelet world..........</h3>
  </ui:define>
  <ui:define name="face2">Enter UserID :<br/>
   <h:inputText id="it" /><br/><br/>
   </ui:define>
   <ui:define name="face3">Enter Password :<br/>
   <h:inputSecret id="is" /><br/><br/>
   </ui:define>
  <ui:define name="face4">
   <h:commandButton id="b" value="Submit" />
  </ui:define>
   </ui:composition>
</body>
</html>

但是当我在 insert.xhtml 中使用 &lt;include src="compose.xhtml"&gt; 标记时,它会显示完整的 facelet。但包含标记只有在我这样写时才有效

<insert name="face1">
<include src="compose.xhtml"/>
</insert>

如果我在包含之前删除 insert 标记,那么包含也不起作用。我对 JSF 2.0 facelets 的这种奇怪行为感到恶心。请帮助我
谢谢

【问题讨论】:

    标签: jsf jakarta-ee jsf-2 facelets


    【解决方案1】:

    首先,您需要了解标签中的“模板”属性是可选的,因此这意味着您的代码中存在一些错误。正如您所知,facelet 将仅包含标签之间的部分,所以

    xmlns="http://www.w3.org/1999/xhtml" 
       xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:h="http://java.sun.com/jsf/html"
    

    这应该带有组合而不是在 html 标记中。
    您的问题类似于this question。我希望这对您也有帮助。
    谢谢

    【讨论】:

      【解决方案2】:

      尝试学习本教程,如果您是 JSF 2 模板的新手,这将非常有帮助。 Here is the link.

      我认为问题出在您尝试使用的模板的路径中:

      <ui:composition template="insert.xhtml">
      

      应该是:

      <ui:composition template="/insert.xhtml">
      

      如果模板在根文件夹中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-10-06
        • 2012-07-15
        • 2011-12-11
        • 2012-06-18
        • 1970-01-01
        • 2017-01-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多