问题
viewId已在应用程序范围内解决。 Resolve只发生一次,而不是每次都发生
任务
将JSF 1.2(Sun.RI)应用程序迁移到JSF2.0(Myfaces)。此应用程序使用自定义FacletContext,DefaultFaceletFactory,DefaultFactory和自定义ResourceResolver覆盖了FacesViewHandler。
我们根据会话数据为viewId提供自定义内容
例如:
浏览器需要viewId order.jsf,应用程序将此viewId解析为order_advanced.jsf。但是在浏览器中只有order.jsf可见。
这很容易实现。我们使用MappingBean来映射viewIds。这个MappingBean在会话启动时被实例化,Resolver使用这个Mapping Bean。
我们拥有什么:
自定义ResourceResolver
@Override
public URL resolveUrl(final String path) {
final PageMappingBean pmb = (PageMappingBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(
"pageMappingBean");
URL returnURL = _resolver.resolveUrl(pmb != null ? pmb.mapUrl(path) : path);
return returnURL;
}
观察
访问映射的viewid适用于第一个会话。它被映射和解决
使用不同的映射启动新会话不再解析viewid。
这是由于方法(From Myfaces)
public Facelet getFacelet(String uri){
URL url = (URL) _relativeLocations.get(uri);
if (url == null)
{
url = resolveURL(_baseUrl, uri);
if (url != null)
{
Map<String, URL> newLoc = new HashMap<String, URL>(_relativeLocations);
newLoc.put(uri, url);
_relativeLocations = newLoc;
}
else
{
throw new IOException("'" + uri + "' not found.");
}
}
return this.getFacelet(url);
}
问题
我们如何在 Myfaces (生产性和测试环境)中覆盖上述方法。如上所述,我们已经为JSF1.2做了这个,但在JSF 2.0中还有额外的VDL层。
或者还有其他方法可以解决问题吗?
注意
FacesFlow可能是我们问题的解决方案,但它不能在WAS8.0应用服务器中使用,我们不允许:-(
对于Mojarra(RI),我们有一个解决方案。在那里可以设置context-param com.sun.faces.faceletFactory。此解决方案适用于我们,但只能用于开发环境。生产和测试基于Myfaces。
目前我们已经放弃了使用applicationcoped FaceletFactory的想法。我们正在使用facelets的动态分辨率:
<ui:component xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<ui:include src="#{faceletMapper.map('/pagetoload.xhtml')}"/>
</ui:component>
答案 0 :(得分:0)
我们不再使用自定义FacletFactory。 我们现在正在动态扩展facelets。 Outr Mapping Bean只是一个普通的bean,用于决定包含哪个facelet