javax.faces.view.facelets.FaceletException: Error

2019-01-15 20:46发布

I would like to create table which can display data from database into JSF page. I found this code:

<h:dataTable value="#{bookStore.items}" var="store">
  <h:column>
    <f:facet name="header">
      <h:outputText  value="#{msg.storeNameLabel}"/>
    </f:facet>
    <h:outputText value="#{store.name}"/>
  </h:column>
  <h:column>
    <f:facet name="header">
      Subject
    </f:facet>
    <h:outputText value="#{store.subject}"/>
  </h:column>
  <h:column>
    <f:facet name="header">
      <h:outputText  value="#{msg.storePriceLabel}"/>
    </f:facet>
    <h:outputText value="#{store.price}"/>
  </h:column>
</h:dataTable> 

When I use this code I get this error message in Netbeans:

javax.faces.view.facelets.FaceletException: Error Parsing /my.xhtml: Error Traced[line: 42] The prefix "f" for element "f:facet" is not bound

If I replace the f tag with h tag, is it going to work? Or do I have to include f tag library?

3条回答
混吃等死
2楼-- · 2019-01-15 21:13

Include taglib. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

查看更多
Lonely孤独者°
3楼-- · 2019-01-15 21:16

Replacing the f with h won't work, since there's no h:facet (in the JSF html taglib which is likely to be assigned to the h prefix). You'll have to include the appropriate taglib (JSF core) and assign it to the f prefix.

查看更多
来,给爷笑一个
4楼-- · 2019-01-15 21:17

You have to inlude the correct taglib for the f prefix.

Here is an example for a JSF 2.2 Facelet page:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

...
</html>

In case you're still on JSF 2.0/2.1, use java.sun.com domain instead of xmlns.jcp.org domain in XML namespace.

I recommend to read a JSF tutorial, you can find links in our JSF wiki page.

查看更多
登录 后发表回答