NullPointerException in MyFaces facelet inclusion

后端 未结 1 1106
感动是毒
感动是毒 2021-01-24 02:46


I\'m trying to migrate simple JSF2.2 prototype from Mojarra 2.2.5 (... where works fine ...) to MyFaces 2.2.3 but a NullPointerEx

相关标签:
1条回答
  • 2021-01-24 03:36

    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.

    0 讨论(0)
提交回复
热议问题