FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot root=context.getViewRoot();//获得前台页面的文件名
List list=root.getChildren();
HtmlForm form=(HtmlForm)list.get(0);//获得<form>节点
list=form.getChildren();
for(int i=0;i<list.size();i++){
UIComponent out=(UIComponent)list.get(i);
if(out instanceof HtmlOutputText){//判断节点类型
System.out.println(out.getId()+"该节点类型为:"+out.getClass());
}
}
UIViewRoot root=context.getViewRoot();//获得前台页面的文件名
List list=root.getChildren();
HtmlForm form=(HtmlForm)list.get(0);//获得<form>节点
list=form.getChildren();
for(int i=0;i<list.size();i++){
UIComponent out=(UIComponent)list.get(i);
if(out instanceof HtmlOutputText){//判断节点类型
System.out.println(out.getId()+"该节点类型为:"+out.getClass());
}
}
本文介绍了一种在JavaServer Faces(JSF)中遍历页面元素的方法,通过获取当前实例并利用UIViewRoot来访问页面上的所有组件。示例代码展示了如何获取<form>节点及其子元素,并对特定类型的UI组件进行操作。
221

被折叠的 条评论
为什么被折叠?



