从xhtml文件创建jsf视图/组件树 [英] creating jsf view/Component tree from the xhtml file

查看:127
本文介绍了从xhtml文件创建jsf视图/组件树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在应用程序启动时访问jsf页面组件树.我在网上找到了这个来源

I need to access jsf pages component tree on application start up. I found this source on the net

   UIViewRoot viewRoot = context.getApplication().getViewHandler().createView(context, "/path/to/some.xhtml");

,但生成的viewRoot没有任何子代. 有人知道什么是最好的方法吗?

but the resulting viewRoot doesn't have any children. Does anybody know what is the best way to do it?

谢谢.

推荐答案

您忘记了构建视图.您可以使用

You forgot to build the view. You can use ViewDeclarationLanguage#buildView() for this. Here's an extract of its javadoc (emphasis mine):

采取特定于此VDL实现的任何操作,以引起参数UIViewRoot,该参数必须已经通过调用

Take any actions specific to this VDL implementation to cause the argument UIViewRoot which must have been created via a call to createView(javax.faces.context.FacesContext, java.lang.String), to be populated with children.

因此,这应该做到:

String viewId = "/path/to/some.xhtml";
FacesContext context = FacesContext.getCurrentInstance();
ViewHandler viewHandler = context.getApplication().getViewHandler();

UIViewRoot view = viewHandler.createView(context, viewId);
viewHandler.getViewDeclarationLanguage(context, viewId).buildView(context, view);
// view should now have children.

您还可以使用

You can by the way also use the ViewDeclarationLanguage#createView() directly to create the view instead of the ViewHandler#createView() shorthand.

String viewId = "/path/to/some.xhtml";
FacesContext context = FacesContext.getCurrentInstance();
ViewDeclarationLanguage vdl = context.getApplication().getViewHandler().getViewDeclarationLanguage(context, viewId);

UIViewRoot view = vdl.createView(context, viewId);
vdl.buildView(context, view);
// view should now have children.

这篇关于从xhtml文件创建jsf视图/组件树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆