开发者

Not able to add HTML to <ui:define>

开发者 https://www.devze.com 2023-04-12 15:13 出处:网络
I have recently started working with JSF2.0 and Facelets, but have run into what I hope is an easy answer for most of you out there.When I am trying to add any HTML tag within a <ui:define> tag

I have recently started working with JSF2.0 and Facelets, but have run into what I hope is an easy answer for most of you out there. When I am trying to add any HTML tag within a <ui:define> tag I receive the following error:

javax.faces.view.facelets.TagException: /content/home/test.xhtml @11,10 Tag Library supports namespace: http://java.sun.com/jsf/facelets, but no tag was defined for name: div

If I remove all of the HTML tags from the section the page displays correctly. Here is my simple page that I have been trying to get working:

<!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:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:jrc="http://com.comanche.web.components"> 
<ui:composition template="/templates/masterLayout.xhtml" xmlns="http://java.sun.com/jsf/facelets">      

    <ui:define name="windowTitle">Home</ui:define>
    <ui:define name="c开发者_开发百科ontent">
            <div>I want to add HTML and am having lots of trouble.</div>
    </ui:define>
</ui:composition>
</html>

I know I should be able to add HTML within the define tag. What do I need to do to get HTML in without any errors.


Your <ui:composition> declaration is using the wrong global XML namespace. You definied http://java.sun.com/jsf/facelets as global XML namespace while it should have been assigned to ui: XML namespace. The <div> tag doesn't exist in the Facelets taglib (which is what the exception is trying to tell you). You should have assigned http://www.w3.org/1999/xhtml as global XML namespace. Further, the <!DOCTYPE> and <html> will be ignored anyway. The sole content of the file should be the following:

<ui:composition template="/templates/masterLayout.xhtml" 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets">      

    <ui:define name="windowTitle">Home</ui:define>
    <ui:define name="content">
        <div>I want to add HTML and am having lots of trouble.</div>
    </ui:define>
</ui:composition>

Nothing before or after <ui:composition> in the very same file is necessary.

See also:

  • How to include another XHTML in XHTML using JSF 2.0 Facelets?
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号