jsf ActionListener 查找正确的UIComponent
2015-12-27 14:10
489 查看
package com.xiuye.jsf.listener; import javax.faces.component.UIComponent; import javax.faces.component.UIOutput; import javax.faces.component.UIViewRoot; import javax.faces.component.html.HtmlBody; import javax.faces.component.html.HtmlForm; import javax.faces.component.html.HtmlOutputLabel; import javax.faces.context.FacesContext; import javax.faces.event.AbortProcessingException; import javax.faces.event.ActionEvent; import javax.faces.event.ActionListener; public class MyActionListener implements ActionListener{ @Override public void processAction(ActionEvent arg0) throws AbortProcessingException { FacesContext fc = FacesContext.getCurrentInstance(); UIViewRoot root = fc.getViewRoot(); UIComponent comp = root.findComponent("OK"); /*System.out.println(root.getChildCount()); System.out.println(root.getClientId()); System.out.println(root.getId()); System.out.println(root.getChildren().get(1)); System.out.println(root.getChildren().get(2)); System.out.println(root.getChildren().get(3));*/ //HtmlOutputLabel out = (HtmlOutputLabel)comp; //xhtml文件跟元素从<html>,h:head, h:body,</html>开始 //jsp从<f:view>开始 for(UIComponent c : root.getChildren()) { if(c instanceof HtmlBody){ for(UIComponent i : c.getChildren()){ //System.out.println(i); if(i instanceof HtmlForm){ HtmlOutputLabel label = (HtmlOutputLabel) i.findComponent("OK"); if(label != null){ label.setValue("rrrrrrrrrrrrrrrr"); } } } } //System.out.println(c); } //out.setValue("123456"); } }
相关文章推荐
- UINavigationController(导航控制器)
- Implement Stack using Queues 用队列实现栈
- CUICatalog: Invalid asset name supplied: (null)
- C#_Dictionary<TKey, TValue>的使用
- 允许 UIAccess 应用程序在提升时进行提示,而无需使用安全桌面
- UIView
- 为OLED屏增加GUI支持2:2D图形库
- UISwitch
- UIButton
- 使用EasyUI实现加入和删除功能
- android127 zhihuibeijing 屏幕适配
- UIKit - UIImage 详解
- Win10系统下软件UI显示不完整解决方案
- CALayer与UIView及一些基本的3D变换
- Arduino - 中断的使用
- miniui datagrid 保存到服务端,使用.NET 自带 JSON 转换时发现日期格式不兼容。
- C#操作xml文档,cuid,dategridview显示数据
- C#操作xml文档,cuid,dategridview显示数据
- Winform实现多线程异步更新UI(进度及状态信息)
- UIGestureRecognizer,手势处理,点击,长按,拖动,左右划动