加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 从xhtml文件创建jsf视图/组件树

发布时间:2020-12-15 03:04:07 所属栏目:Java 来源:网络整理
导读:我需要在应用程序启动时访问jsf页面组件树.我在网上找到了这个来源 UIViewRoot viewRoot = context.getApplication().getViewHandler().createView(context,"/path/to/some.xhtml"); 但是生成的viewRoot没有任何子节点. 有谁知道最好的方法是什么? 谢谢. 解
我需要在应用程序启动时访问jsf页面组件树.我在网上找到了这个来源
UIViewRoot viewRoot = context.getApplication().getViewHandler().createView(context,"/path/to/some.xhtml");

但是生成的viewRoot没有任何子节点.
有谁知道最好的方法是什么?

谢谢.

解决方法

你忘了构建视图了.您可以使用 ViewDeclarationLanguage#buildView().这是 javadoc(强调我的)的摘录:

Take any actions specific to this VDL implementation to cause the argument UIViewRoot which must have been created via a call to 07002,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.

你可以顺便使用ViewDeclarationLanguage#createView()直接创建视图而不是ViewHandler#createView()的速记.

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读