Christopher Klewes
Christopher Klewes

Reputation: 11445

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. We now have Mojarra, Tomahawk 2.0 1.1.11, Spring Webflow / Faces 2.3.0 and JSF 2.0.

I followed the upgrading tutorial from BalusC. The first step was to fix the the web.xml and move to 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.

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

This is one of my *.jspx files.

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

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!

Upvotes: 1

Views: 5588

Answers (2)

lu4242
lu4242

Reputation: 2318

The problem to deal with .jspx files was handled in JSF 2.1, thanks to some guys that maintains MyFaces Trinidad. See Appendix A 1.2.1.1 The facelets-processing element. Enabling this, you can read .jspx files with facelets engine and keep changes to minimal. In few words just add this on your 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.

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

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.

If you have more questions about this you can suscribe to MyFaces Users and Dev Mailing Lists and ask questions there.

Upvotes: 1

BalusC
BalusC

Reputation: 1109532

You're using JSPX instead of Facelets. This is not going to work flawlessly on 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. Remove also that javax.faces.DEFAULT_SUFFIX context param which defaults to .xhtml already.

Upvotes: 2

Related Questions