我們決定升級到JSF 2.0,但不幸的是這種方式效果不佳。我們現在有Mojarra,Tomahawk 2.0 1.1.11,Spring Webflow/Faces 2.3.0和JSF 2.0。我跟着upgrading tutorial from BalusC。第一步是修復web.xml
並轉移到Servlet API 2.5。從JSF 1.2遷移到2.0的問題
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/facelets-taglibs/custom.taglib.xml</param-value>
</context-param>
<!-- Use JSF view templates saved as *.xhtml, for use with Facelets -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xml</param-value>
</context-param>
之後,我替換了依賴關係並使用了新版本的JSF。
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.3</version>
</dependency>
我調整了我們的自定義標籤庫,並遷移到新的XML模式定義,
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd">
<namespace>http://www.custom.org/facelets-taglib</namespace>
[...]
我也做所有更改faces-config.xml
。
這是我的其中一個*.jspx
文件。
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" version="2.0"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:sf="http://www.springframework.org/tags/faces"
xmlns:os="http://www.custom.org/facelets-taglib">
[...]
${os:json()}
</html>
在遷移之前,此文件運行良好,它是對特定函數的調用。現在它打印:
Caused by: javax.faces.FacesException: /WEB-INF/views/example.jspx(10,2)
The attribute prefix os does not correspond to any imported tag library
at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:136)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:115)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
at org.springframework.faces.webflow.FlowLifecycle.render(FlowLifecycle.java:80)
at org.springframework.faces.webflow.JsfView.render(JsfView.java:90)
at org.springframework.webflow.engine.ViewState.render(ViewState.java:296)
at org.springframework.webflow.engine.ViewState.refresh(ViewState.java:243)
at org.springframework.webflow.engine.ViewState.resume(ViewState.java:221)
at org.springframework.webflow.engine.Flow.resume(Flow.java:545)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:261)
... 67 more
Caused by: org.apache.jasper.JasperException: /WEB-INF/views/example.jspx(10,2)
The attribute prefix os does not correspond to any imported tag library
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
at org.apache.jasper.compiler.Validator$ValidateVisitor$1FVVisitor.visit(Validator.java:1509)
at org.apache.jasper.compiler.ELNode$Function.accept(ELNode.java:129)
at org.apache.jasper.compiler.ELNode$Nodes.visit(ELNode.java:200)
at org.apache.jasper.compiler.ELNode$Visitor.visit(ELNode.java:242)
at org.apache.jasper.compiler.ELNode$Root.accept(ELNode.java:56)
你可以給我任何暗示我錯過了什麼或可能的bug可能隱藏的地方嗎?非常感謝你!
這個異常基本上說明找不到'/ WEB-INF/facelets-taglibs/custom.taglib.xml'。你確定文件名是正確的,並且名稱空間是正確的(區分大小寫!)。我也看到你正在使用Maven,你能確保'/WEB-INF/facelets-taglibs/custom.taglib。目標容器中已部署的WAR文件中是否真的存在xml文件? – BalusC
該名稱是definetily正確的,我只使它匿名,通過刪除項目名稱。命名空間是正確的(並且區分大小寫)。 'custom.taglib.xml'也在部署的戰爭中。我們還有'SpringApplication',它擴展了javax.faces.application.Application.Application,它從spring中加載了一些組件。會有錯誤嗎?或者沒有正確實施的新方法? – codevour
等等......您正在使用JSPX而不是Facelets!不確定這是否是因爲我從未將JSX用於JSF2,但嘗試將'.jspx'重命名爲'.xhtml'(並且還刪除了現在多餘的'xmlns:jsp' taglib)。除去'javax.faces.DEFAULT_SUFFIX'上下文參數。它已經默認爲'.xhtml'。讓我知道如果解決了這個問題,那麼我會把這個評論變成一個答案。 – BalusC