NullPointerException in MyFaces facelet inclusion

喜你入骨 提交于 2019-12-02 03:20:50

It is not a bug. Use FaceletContext is the wrong way to do it, because later it causes duplicate id and state management issues, that does not have solution because from start the code is wrong. Instead, try use this way:

        ViewDeclarationLanguage vdl = facesContext.getApplication().
            getViewHandler().getViewDeclarationLanguage(
                facesContext, facesContext.getViewRoot().getViewId());

        Map<String, Object> attributes = new HashMap<String, Object>();
        attributes.put("src", "/addSimpleIncludeVDL_1_1.xhtml");
        UIComponent component = vdl.createComponent(facesContext, 
            "http://java.sun.com/jsf/facelets", 
            "include", attributes);
        getChildren().add(component);

vdl.createComponent(...) was added in JSF 2.2, and in MyFaces it was improved to allow this usage. You can even add composite components programmatically in this way. In MyFaces users list it has been reported that this way works very well.

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