Migrating from facelets 1.1 to faclets 2.0 - FaceletViewHandler

天大地大妈咪最大 提交于 2019-12-21 10:49:39

问题


I have read the following post which was very helpful Migrating from JSF 1.2 to JSF 2.0

but I am having a problem with the migration as I have a custom view handler which extends from FaceletViewHandler - this is not part of faclets 2.

I am migrating on JBoss 4.2.2 the following: - JSF 1.2 to JSF 2.0

I also want to migrate the faclets - which i have a problem described above.

In my application, I am also using Tomahawk - is there any problem with this migration?

Thanks in advance.

Elico.


回答1:


Right, you need to replace FaceletViewHandler by ViewHandlerWrapper.

So the following basic FaceletViewHandler implementation:

import javax.faces.application.ViewHandler;
import com.sun.facelets.FaceletViewHandler;

public class MyViewHandler extends FaceletViewHandler {

    public MyViewHandler(ViewHandler parent) {
        super(parent);
    }

    // ...
}

needs to be updated as follows:

import javax.faces.application.ViewHandler;
import javax.faces.application.ViewHandlerWrapper;

public class MyViewHandler extends ViewHandlerWrapper {

    private ViewHandler wrapped;

    public MyViewHandler(ViewHandler wrapped) {
        this.wrapped = wrapped;
    }

    @Override
    public ViewHandler getWrapped() {
        return wrapped;
    }

    // ...
}

I've updated my answer on the migration question accordingly.




回答2:


To activate MyViewHandler e.g. for JEE7, WEB-INF/faces-config.xml should be defined like:

<?xml version="1.0"?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
          http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
    <application>
        <view-handler>pkg.MyViewHandler</view-handler>
    </application>
</faces-config>


来源:https://stackoverflow.com/questions/6816270/migrating-from-facelets-1-1-to-faclets-2-0-faceletviewhandler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!