简体   繁体   English

从 JSF 1.2 迁移到 2.0 的问题

[英]Problems with migration from JSF 1.2 to 2.0

We decided to upgrade to JSF 2.0, unfortunately this didn't work very well.我们决定升级到 JSF 2.0,不幸的是这不是很好。 We now have Mojarra, Tomahawk 2.0 1.1.11, Spring Webflow / Faces 2.3.0 and JSF 2.0.我们现在有 Mojarra、Tomahawk 2.0 1.1.11、Spring Webflow / Faces 2.3.0 和 JSF 2.0。

I followed the upgrading tutorial from BalusC .我遵循了BalusC 的升级教程 The first step was to fix the the web.xml and move to Servlet API 2.5.第一步是修复web.xml并移动到 Servlet API 2.5。

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

After this I replaced the dependencies and used the new versions of JSF.在此之后,我替换了依赖项并使用了新版本的 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>

I adjusted our custom taglib and migrated to the new XML schema definition,我调整了我们的自定义标签库并迁移到新的 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>

[...]

I've also done all changes to the faces-config.xml .我还对faces-config.xml进行了所有更改。

This is one of my *.jspx files.这是我的*.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>

Before the migration this file worked great, it's a call to a specific function. Now it prints:在迁移之前,此文件运行良好,它是对特定 function 的调用。现在它打印:

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)

Can you give me any hint where I did miss something or where a possible bug could hide?你能给我任何提示吗,我确实遗漏了一些东西或者可能的错误可能隐藏在哪里? Thank you very much!非常感谢你!

You're using JSPX instead of Facelets.您正在使用 JSPX 而不是 Facelets。 This is not going to work flawlessly on JSF 2.0.这不会在 JSF 2.0 上完美运行。 If upgrading to JSF 2.1 where JSPX is been supported is not an option, then you need to rename your .jspx files to .xhtml and remove the now superfluous xmlns:jsp taglib declaration.如果升级到支持 JSPX 的JSF 2.1不是一个选项,那么您需要将.jspx文件重命名为.xhtml并删除现在多余的xmlns:jsp taglib 声明。 Remove also that javax.faces.DEFAULT_SUFFIX context param which defaults to .xhtml already.还删除默认为.xhtmljavax.faces.DEFAULT_SUFFIX上下文参数。

The problem to deal with.jspx files was handled in JSF 2.1, thanks to some guys that maintains MyFaces Trinidad.处理 .jspx 文件的问题已在 JSF 2.1 中得到解决,这要感谢一些维护 MyFaces Trinidad 的人。 See Appendix A 1.2.1.1 The facelets-processing element.请参阅附录 A 1.2.1.1 facelets-processing 元素。 Enabling this, you can read.jspx files with facelets engine and keep changes to minimal.启用此功能后,您可以使用 facelets 引擎读取 .jspx 文件并将更改保持在最低限度。 In few words just add this on your faces-config.xml:简而言之,只需将其添加到您的 faces-config.xml 中:

<faces-config-extension>
    <facelets-processing>
        <file-extension>.jspx</file-extension>
        <process-as>jspx</process-as>
    </facelets-processing>
</faces-config-extension>

And maybe configure javax.faces.FACELETS_VIEW_MAPPINGS or javax.faces.DEFAULT_SUFFIX web config param to add the jspx extension.并且可能配置 javax.faces.FACELETS_VIEW_MAPPINGS 或 javax.faces.DEFAULT_SUFFIX web 配置参数以添加 jspx 扩展。

After this, maybe the only problem you could have is translate you old jsp tags into facelets TagHandler, and maybe convert EL functions into facelets functions.在此之后,您可能遇到的唯一问题就是将旧的 jsp 标签转换为 facelets TagHandler,并可能将 EL 函数转换为 facelets 函数。 I think that is an easy task and it is worth to do it.我认为这是一项简单的任务,值得去做。 Note with the other alternative (convert to xhml) anyway you'll need to do this step too.请注意其他替代方法(转换为 xhtml),无论如何您也需要执行此步骤。

This alternative has the advantage that you don't need to change your existing navigation rules or page extensions, so from JSF spec point of view this alternative is preferred.此替代方案的优点是您无需更改现有的导航规则或页面扩展,因此从 JSF 规范的角度来看,此替代方案是首选。

If you have more questions about this you can suscribe to MyFaces Users and Dev Mailing Lists and ask questions there.如果您对此有更多疑问,可以订阅MyFaces Users 和 Dev Mailing Lists并在那里提问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM