如何在ADF页面中显示警告信息?
来源:互联网 发布:python 2 3区别 编辑:程序博客网 时间:2024/06/05 04:38
运行环境:JDeveloper 11.1.2.1.0 + Oracle Database 10g Express Edition 10.2.0.1。
我以《使用ADF实现基于Form的CRUD (3)》的项目代码为例,展示如何在ADF页面中显示警告信息。
1. 显示在某个组件的旁边
要想显示在组件的旁边,首先要得到这个组件的id或clientId,然后就是构造FacesMessage,并显示出来。
1.1 组件已经绑定在Managed Bean中
为某个组件设置Binding的方法如下:
选中该组件,找到Binding属性,然后选择或创建Managed Bean和属性名称。
我这里选择了两个组件,一个是按钮,一个是InputText。
修改lastButton_actionListener方法如下:
测试结果:使用按钮时,不知为何警告信息始终显示在页面中央;使用InputText时,警告信息显示在组件旁边。
使用按钮时,
使用InputText时,
1.2 通过组件上的事件获取组件
测试结果和1.1一样:使用按钮时,不知为何警告信息始终显示在页面中央;使用InputText时,警告信息显示在组件旁边。
1.3 使用JSFUtils.getRootViewComponentId 获取根组件id
1.4 使用JSFUtils.findComponentInRoot获取根组件对象
2. 显示在页面中央,以弹出窗口的形式,适用于全局性的重要提示或错误警告
只要调用addMessage时,第一个参数赋值为null就可以了,其它的代码不变。
Project 下载:Form_CRUD(popupMessage).7z
参考文献:
1. http://adfjsf.blogspot.com/2009/08/programmatic-error-message-in-adf-11g.html
我以《使用ADF实现基于Form的CRUD (3)》的项目代码为例,展示如何在ADF页面中显示警告信息。
1. 显示在某个组件的旁边
要想显示在组件的旁边,首先要得到这个组件的id或clientId,然后就是构造FacesMessage,并显示出来。
1.1 组件已经绑定在Managed Bean中
为某个组件设置Binding的方法如下:
选中该组件,找到Binding属性,然后选择或创建Managed Bean和属性名称。
我这里选择了两个组件,一个是按钮,一个是InputText。
修改lastButton_actionListener方法如下:
public void lastButton_actionListener(ActionEvent actionEvent) { if (!isDirty()) { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Last"); Object result = operationBinding.execute(); } else { //popupMessage(lastButton.getId(),Save_Or_Undo_Message); popupMessage(maxSalaryInputText.getId(),Save_Or_Undo_Message); //popupMessage(actionEvent,Save_Or_Undo_Message); } } public void popupMessage(String clientId, String message) { FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_INFO, message, null)); }
测试结果:使用按钮时,不知为何警告信息始终显示在页面中央;使用InputText时,警告信息显示在组件旁边。
使用按钮时,
使用InputText时,
1.2 通过组件上的事件获取组件
public void lastButton_actionListener(ActionEvent actionEvent) { if (!isDirty()) { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Last"); Object result = operationBinding.execute(); } else { //popupMessage(lastButton.getId(),Save_Or_Undo_Message); //popupMessage(maxSalaryInputText.getId(),Save_Or_Undo_Message); popupMessage(actionEvent,Save_Or_Undo_Message); } } public void popupMessage(ActionEvent actionEvent, String message) { FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(actionEvent.getComponent().getClientId(context), new FacesMessage(FacesMessage.SEVERITY_INFO, message, null)); }
测试结果和1.1一样:使用按钮时,不知为何警告信息始终显示在页面中央;使用InputText时,警告信息显示在组件旁边。
1.3 使用JSFUtils.getRootViewComponentId 获取根组件id
public void lastButton_actionListener(ActionEvent actionEvent) { if (!isDirty()) { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Last"); Object result = operationBinding.execute(); } else { //popupMessage(lastButton.getId(),Save_Or_Undo_Message); //popupMessage(maxSalaryInputText.getId(),Save_Or_Undo_Message); //popupMessage(actionEvent,Save_Or_Undo_Message); popupMessage(JSFUtils.getRootViewComponentId(),Save_Or_Undo_Message); } }
1.4 使用JSFUtils.findComponentInRoot获取根组件对象
public void lastButton_actionListener(ActionEvent actionEvent) { if (!isDirty()) { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("Last"); Object result = operationBinding.execute(); } else { System.out.println(JSFUtils.getRootViewComponentId()); //popupMessage(lastButton.getId(),Save_Or_Undo_Message); //popupMessage(maxSalaryInputText.getId(),Save_Or_Undo_Message); //popupMessage(actionEvent,Save_Or_Undo_Message); //popupMessage(JSFUtils.findComponentInRoot(lastButton.getId()).getClientId(),Save_Or_Undo_Message); popupMessage(JSFUtils.findComponentInRoot(maxSalaryInputText.getId()).getClientId(),Save_Or_Undo_Message); } }
2. 显示在页面中央,以弹出窗口的形式,适用于全局性的重要提示或错误警告
只要调用addMessage时,第一个参数赋值为null就可以了,其它的代码不变。
public void popupMessage(String message) { FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, message, null)); }
Project 下载:Form_CRUD(popupMessage).7z
参考文献:
1. http://adfjsf.blogspot.com/2009/08/programmatic-error-message-in-adf-11g.html
2. http://mukx.blogspot.com/2009/01/adf-10g-how-to-show-faces-message-both.html
http://maping930883.blogspot.com/2009/09/adf044adf.html
0 0
- 如何在ADF页面中显示警告信息?
- Php如何屏蔽页面显示的警告信息
- ADF:如何在一个adf table中标示一个view object有从属的detail信息
- 在页面中显示滚动信息
- 一对多 如何使多的一端信息在页面上同一行中友好显示
- 非ADF控件如何通过回调显示信息
- Salesforce -- VisualForce页面显示错误/警告等信息
- 在jsp页面显示struts中异常信息
- 在全局页面缓存中显示登录信息
- 在JSP页面中显示JavaBean属性信息
- 如何让页面中对话框总显示在页面之上
- 在Xcode中如何屏蔽某个源文件的编译警告信息
- JSF中如何在弹出窗口中显示编辑页面
- 如何在logcat中显示AOSP代码中的打印信息
- 如何在SQL语句中动态显示信息的状态
- 如何在ADF中使用Sequence自动增长
- ADF中页面导航总结
- ADF中页面导航总结
- POJ 3623 Best Cow Line, Gold(模拟)
- 2014-08-19 19:33:41
- HDU 4965 Fast Matrix Calculation 矩阵快速幂
- 使用ADF实现基于Form的CRUD (3)
- Codeforces 4C (STL map)
- 如何在ADF页面中显示警告信息?
- ADF与JSF的区别
- Java为什么要使用内部类?
- 使用github之:Git分支管理策略
- Regular Expression Matching
- ADF工具类:JSFUtil.java 源代码
- Chrome插件开发
- 程序员生存定律-六个程序员的故事(1)
- java中关于Map的九大问题