【问题标题】:Avoid multiple DOCTYPE and html tags when using ui:include使用 ui:include 时避免使用多个 DOCTYPE 和 html 标签
【发布时间】:2011-10-29 13:08:52
【问题描述】:

我们在“主”页面中使用了几个ui:include 标签。要包含的页面如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=".." xmlns:ui="..." ...>
    <ui:fragment rendered="${foo}">
       some html code
    </ui:fragement>
    <ui:fragment rendered="${!foo || bar}">
       some more html code
    </ui:fragement>
</html>

使用ui:include 进行模板会导致在源代码中多次重复DOCTYPEhtml 标记,这非常难看。 (当然,用户看不到,但我是 tidy html 的粉丝)

但是,如果我从 to-be-included-xhtml 中删除 DOCTYPEhtml 标记,Faces Servlet 会引发异常,指出 ui:fragment 的前缀 ui 未绑定。

有人知道,我如何在没有多个DOCTYPEs 和htmls 的情况下包含另一个XHTML 页面?

【问题讨论】:

    标签: jsf-2 facelets


    【解决方案1】:

    你应该看看 ui:composition 标签。 我们还使用 ui:include 来包含 jsf2 页面,为了解决您遇到的问题,我相信您可以通过添加 ui:composition 标签来更改包含的页面,如下所示:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns=".." xmlns:ui="..." ...>
        <ui:composition>
        <ui:fragment rendered="${foo}">
           some html code
        </ui:fragement>
        <ui:fragment rendered="${!foo || bar}">
           some more html code
        </ui:fragement>
        </ui:composition>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2016-07-25
      • 2013-03-16
      • 2017-07-31
      • 1970-01-01
      • 2012-10-02
      • 2011-01-16
      • 1970-01-01
      • 2015-06-13
      • 1970-01-01
      相关资源
      最近更新 更多