Tags from http://xmlns.jcp.org namespace do not re

2019-05-04 18:06发布

问题:

I have this:

<html 
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
>
<h:selectOneRadio>
    <f:selectItem value="1" itemValue="1" itemLabel="123"/>
    <f:selectItem value="2" itemValue="2" itemLabel="321"/>
</h:selectOneRadio>

And I get this:

<f:selectItem value="1" itemValue="1" itemLabel="123"></f:selectItem>
<f:selectItem value="2" itemValue="2" itemLabel="321"></f:selectItem>
<select name="j_idt5" size="1"></select>

Why are xmlns:f="http://xmlns.jcp.org/jsf/core" tags not rendered?

I'm using JBoss AS 7 on Netbeans 7.3.

回答1:

The new XML namespace domain http://xmlns.jcp.org in JSF taglib URIs is introduced in JSF 2.2 which is part of Java EE 7. JBoss AS 7 as being a Java EE 6 compliant application server does not ship with JSF 2.2 bundled, but with JSF 2.1. Therefore the new XML namespace domain does not work at all. Also the new JSF 2.2 specific features such as passthrough elements and attributes won't work at all.

You need to use the JSF 2.1 compatible XML namespace domain http://java.sun.com. Here's the complete set:

<html 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"
>

I'm not sure why you attempted to use the new JSF 2.2 XML namespaces. Perhaps you incorrectly read a JSF 2.2 targeted tutorial (e.g. Oracle Java EE 7 tutorial) instead of a JSF 2.0/2.1 targeted one (e.g. Oracle Java EE 6 tutorial). Pay carefully attention that the versions match.

If you really intend to use JSF 2.2 on a JBoss server, then you should basically be upgrading the old JBoss AS 7 to its Java EE 7 compatible successor WildFly 8. Alternatively, manually upgrade the bundled JSF libraries of JBoss AS 7 to a newer version as instructed here: Upgrade JSF / Mojarra in JBoss AS / EAP / WildFly.



回答2:

please look in WEB-INF Folder there is web.xml if there is no such file ,jsf is not renders many maven archetype for jboss have not this file create this file in WEB-INF Folder sample:

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

<display-name>JavaServerFaces</display-name>

<!-- Change to "Production" when you are ready to deploy -->
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<!-- Welcome page -->
<welcome-file-list>
    <welcome-file>faces/hello.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>