<f:facet>标记库支持命名空间:http://java.sun.com/jsf/html,但没有为name定义标记:facet </f:facet>

时间:2012-11-29 22:30:39

标签: jsf

我正在https://www.primefaces.org/showcase/ui/overlay/dialog/loginDemo.xhtml测试PrimeFaces示例。我在Eclipse Dyamic web项目中正确导入了PrimeFaces和JSF 2.1,但是在启动网页时出现了以下错误(使用Tomcat):

javax.faces.view.facelets.TagException: /login.xhtml at line 30 and column 36 <f:facet> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: facet
        org.apache.myfaces.view.facelets.compiler.CompilationManager.pushTag(CompilationManager.java:282)
        org.apache.myfaces.view.facelets.compiler.SAXCompiler$CompilationHandler.startElement(SAXCompiler.java:250)
        com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
        com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
        com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:376)
        com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2717)
        com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
        com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
        com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
        com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
        com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
        com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
        com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
        com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
        com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
        javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
        org.apache.myfaces.view.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:739)
        org.apache.myfaces.view.facelets.compiler.Compiler.compile(Compiler.java:128)
        org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory._createFacelet(DefaultFaceletFactory.java:300)
        org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.access$000(DefaultFaceletFactory.java:53)
        org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory$1.newInstance(DefaultFaceletFactory.java:114)
        org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory$1.newInstance(DefaultFaceletFactory.java:111)
        org.apache.myfaces.view.facelets.impl.FaceletCacheImpl.getFacelet(FaceletCacheImpl.java:83)
        org.apache.myfaces.view.facelets.impl.FaceletCacheImpl.getFacelet(FaceletCacheImpl.java:50)
        org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:199)
        org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:182)
        org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage._getFacelet(FaceletViewDeclarationLanguage.java:2622)
        org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.buildView(FaceletViewDeclarationLanguage.java:452)
        org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:78)
        org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:241)
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:199)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.21 logs.

LoginBean.java包含:

package classi;
import java.awt.event.ActionEvent;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;
public class LoginBean
{
    private String username;  

    private String password;  

    public String getUsername() {  
        return username;  
    }  

    public void setUsername(String username) {  
        this.username = username;  
    }  

    public String getPassword() {  
        return password;  
    }  

    public void setPassword(String password) {  
        this.password = password;  
    }  

    public void login(ActionEvent actionEvent) {  
        RequestContext context = RequestContext.getCurrentInstance();  
        FacesMessage msg = null;  
        boolean loggedIn = false;  

        if(username != null  &&/*&&*/ username.equals("admin") && password != null  && password.equals("admin")) {  
            loggedIn = true;  
            msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", username);  
        } else {  
            loggedIn = false;  
            msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Invalid credentials");  
        }  

        FacesContext.getCurrentInstance().addMessage(null, msg);  
        context.addCallbackParam("loggedIn", loggedIn);  
    }  
}

login.xhtml包含:

<?xml version="1.0" encoding="UTF-8" ?>
<!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/html"
xmlns:p="http://primefaces.org/ui">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h:outputLink id="loginLink" value="javascript:void(0)" onclick="dlg.show()" title="login">     
    <p:graphicImage value="/images/login.png" />  
</h:outputLink>  

<p:growl id="growl" showDetail="true" life="3000" />  

<p:dialog id="dialog" header="Login" widgetVar="dlg">  
    <h:form>  

        <h:panelGrid columns="2" cellpadding="5">  
            <h:outputLabel for="username" value="Username:" />  
            <p:inputText value="#{loginBean.username}"   
                    id="username" required="true" label="username" />  

            <h:outputLabel for="password" value="Password:" />  
            <h:inputSecret value="#{loginBean.password}"   
                    id="password" required="true" label="password" />  

            <f:facet name="footer">  
                <p:commandButton id="loginButton" value="Login" update=":growl"   
                    actionListener="#{loginBean.login}"   
                    oncomplete="handleLoginRequest(xhr, status, args)"/>  
            </f:facet>

        </h:panelGrid>  

    </h:form>  
</p:dialog>  

<script type="text/javascript">  
    function handleLoginRequest(xhr, status, args) {  
        if(args.validationFailed || !args.loggedIn) {  
            jQuery('#dialog').effect("shake", { times:3 }, 100);  
        } else {  
            dlg.hide();  
            jQuery('#loginLink').fadeOut();  
        }  
    }  
</script>  
</body>
</html>

1 个答案:

答案 0 :(得分:6)

尝试将xmlns:f="http://java.sun.com/jsf/html"更改为xmlns:f="http://java.sun.com/jsf/core">