呈现自定义组件时,FacesContext defaultFacesContext为null

时间:2019-01-14 00:27:28

标签: spring spring-mvc jsf upgrade jsf-1.2

我们有一个模板化的标头内容,它使用一个自定义JSF组件,该组件无法推送到EL,因为它无法获取Faces上下文属性。

我已经为Spring 4.3注释转换了一些旧的POJO,扩展了Spring 3.0中的SimpleFormController类:

Link to example Spring Simple Form Controller conversion

我已经调试了FacesContext类,以了解原因,并且jsf-api 2.0类使用defaultFacesContext获取属性,但其值为null。 在升级之前,这是库jsf-api 1.2_15

AppConfig.java


@Configuration
public class ApplicationConfig {

    @Bean
    public UrlBasedViewResolver urlBasedViewResolver()
    {

    UrlBasedViewResolver res = new UrlBasedViewResolver();
    res.setViewClass(JsfView.class);
    res.setPrefix("/WEB-INF/pages/");
    res.setSuffix(".xhtml");

    return res;
}


 FacesContext.java

/**
 * <p class="changed_added_2_0">Return a mutable <code>Map</code> 
 * representing the attributes associated wth this
 * <code>FacesContext</code> instance.  This <code>Map</code> is 
 * useful to store attributes that you want to go out of scope when the
 * Faces lifecycle for the current request ends, which is not always the same 
 * as the request ending, especially in the case of Servlet filters
 * that are invoked <strong>after</strong> the Faces lifecycle for this
 * request completes.  Accessing this <code>Map</code> does not cause any 
 * events to fire, as is the case with the other maps: for request, session, and 
 * application scope.  When {@link #release()} is invoked, the attributes
 * must be cleared.</p>
 * 
 * <div class="changed_added_2_0">
 * 
 * <p>The <code>Map</code> returned by this method is not associated with
 * the request.  If you would like to get or set request attributes,
 * see {@link ExternalContext#getRequestMap}.  
 * 
 * <p>The default implementation throws
 * <code>UnsupportedOperationException</code> and is provided
 * for the sole purpose of not breaking existing applications that extend
 * this class.</p>
 *
 * </div>
 * 
 * @throws IllegalStateException if this method is called after
 *  this instance has been released
 *
 * @since 2.0
 */
public Map<Object, Object> getAttributes() {

    if (defaultFacesContext != null) {
        return defaultFacesContext.getAttributes();
    }
    throw new UnsupportedOperationException();

}

....收到错误:

    java.lang.UnsupportedOperationException
    at 
    javax.faces.context.FacesContext.getAttributes(FacesContext.java:141)
    at 

  javax.faces.component.UIComponent.popComponentFromEL(UIComponent.java:1722)
    at 

  javax.faces.component.UIComponentBase.publishAfterViewEvents(UIComponentBase.java:2022)
    at 

  javax.faces.component.UIComponentBase.doPostAddProcessing(UIComponentBase.java:1691)
    at 

  javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:403)

我们希望该组件注册并呈现到浏览器。
我需要用jsf-api 2.0配置jsf veiw处理程序的方式是否有变化?

0 个答案:

没有答案