ADFUtils
import java.text.SimpleDateFormat;
import java.util.Map;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.share.ADFContext;
import oracle.adf.share.logging.ADFLogger;
import oracle.adf.view.rich.component.rich.RichPopup;
import oracle.adf.view.rich.event.QueryEvent;
import oracle.binding.AttributeBinding;
import oracle.binding.BindingContainer;
import oracle.binding.ControlBinding;
import oracle.binding.OperationBinding;
import oracle.jbo.ApplicationModule;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
public class AdfUtil {
public static final ADFLogger LOGGER = ADFLogger.createADFLogger(AdfUtil.class);
public AdfUtil() {
super();
}
public static String getCurrentUser(){
return ADFContext.getCurrent().getSecurityContext().getUserName();
}
public static String getCurrentUserDisplayName(){
return ADFContext.getCurrent().getSecurityContext().getUserProfile().getDisplayName();
}
public static BindingContext getBindingContext(){
return BindingContext.getCurrent();
}
public static BindingContainer getBindingContainer(){
return getBindingContext().getCurrentBindingsEntry();
}
public static DCBindingContainer getDCBindingContainer(){
return (DCBindingContainer)getBindingContainer();
}
public static DCIteratorBinding getDCIteratorBindingByName(String iteratorName){
return getDCBindingContainer().findIteratorBinding(iteratorName) ;
}
public static OperationBinding getOperationBinding(String operationName){
OperationBinding operation = getDCBindingContainer().getOperationBinding(operationName);
return operation;
}
public static oracle.jbo.domain.Date getCurrentDateTime(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
String currentDateStr = simpleDateFormat.format(currentDate);
return new oracle.jbo.domain.Date(currentDateStr);
}
public static FacesContext getFacesContext(){
return FacesContext.getCurrentInstance();
}
public static void setExpressionValue(String expression,Object value){
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
Application application = facesContext.getApplication();
ExpressionFactory elFactory = application.getExpressionFactory();
ValueExpression valueExpression = elFactory.createValueExpression(elContext, expression, Object.class);
Class bindClass = valueExpression.getType(elContext);
if(bindClass.isPrimitive()||bindClass.isInstance(value)){
valueExpression.setValue(elContext, value);
}
}
public static Object getExpressionValue(String expressionStr){
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
Application application = facesContext.getApplication();
ExpressionFactory expressionFactory = application.getExpressionFactory();
ValueExpression valueExpression = expressionFactory.createValueExpression(elContext, expressionStr, Object.class);
return valueExpression.getValue(elContext);
}
public static void showPopup(RichPopup richPopup){
FacesContext facesContext = FacesContext.getCurrentInstance();
ExtendedRenderKitService kitService = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
String scriptStr = "var popup; popup=AdfPage.PAGE.findComponent('"+richPopup.getClientId(facesContext)+"'); popup.show();";
kitService.addScript(facesContext, scriptStr);
return ;
}
public static void addFacesInfoMessage(String messageStr){
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = facesContext.getViewRoot();
String viewId = viewRoot.getViewId();
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_INFO,messageStr,"");
facesContext.addMessage(viewId, facesMessage);
}
public static void addFacesWarmMessage(String messageStr){
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = facesContext.getViewRoot();
String viewId = viewRoot.getViewId();
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_WARN,messageStr,"");
facesContext.addMessage(viewId, facesMessage);
}
public static void addFacesErrorMessage(String messageStr){
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = facesContext.getViewRoot();
String viewId = viewRoot.getViewId();
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,messageStr,"");
facesContext.addMessage(viewId,facesMessage);
}
public static Object getRequestParameterByName(String paraName){
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
Map paraMap = externalContext.getInitParameterMap();
return paraMap.get(paraName);
}
public static void closeCurrentPage(){
FacesContext facesContext = FacesContext.getCurrentInstance();
ExtendedRenderKitService extendService = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
String scriptStr = "window.opener=null;window.open('','_self');window.close();";
extendService.addScript(facesContext,scriptStr);
}
// The code below should be in a Utility clas
public Object invokeMethodExpression(String expr, Class returnType,
Class[] argTypes, Object[] args) {
FacesContext fc = FacesContext.getCurrentInstance();
ELContext elctx = fc.getELContext();
ExpressionFactory elFactory =
fc.getApplication().getExpressionFactory();
MethodExpression methodExpr =
elFactory.createMethodExpression(elctx, expr, returnType,
argTypes);
return methodExpr.invoke(elctx, args);
}
/**
* invokeMethodExpression("#{bindings.ProcessInstanceVO1Query.processQuery}",Object.class, QueryEvent.class, queryEvent);
* @param expr
* @param returnType
* @param argType
* @param argument
* @return
*/
public Object invokeMethodExpression(String expr, Class returnType,
Class argType, Object argument) {
return invokeMethodExpression(expr, returnType,
new Class[] { argType },
new Object[] { argument });
}
public static ApplicationModule getApplicationModuleForDataControl(String name) {
return (ApplicationModule)getExpressionValue("#{data." + name +
".dataProvider}");
}
public static AttributeBinding findControlBinding(BindingContainer bindingContainer,
String attributeName) {
if (attributeName != null) {
if (bindingContainer != null) {
ControlBinding ctrlBinding =
bindingContainer.getControlBinding(attributeName);
if (ctrlBinding instanceof AttributeBinding) {
return (AttributeBinding)ctrlBinding;
}
}
}
return null;
}
public static AttributeBinding findControlBinding(String attributeName) {
return findControlBinding(getBindingContainer(), attributeName);
}
public static void makeCurrent(SelectionEvent selectionEvent) {
RichTable _table = (RichTable)selectionEvent.getSource();
CollectionModel _tableModel = (CollectionModel)_table.getValue();
JUCtrlHierBinding _adfTableBinding =
(JUCtrlHierBinding)_tableModel.getWrappedData();
DCIteratorBinding _tableIteratorBinding =
_adfTableBinding.getDCIteratorBinding();
Object _selectedRowData = _table.getSelectedRowData();
JUCtrlHierNodeBinding _nodeBinding =
(JUCtrlHierNodeBinding)_selectedRowData;
Key _rwKey = _nodeBinding.getRowKey();
if (_rwKey != null) {
_tableIteratorBinding.setCurrentRowWithKey(_rwKey.toStringFormat(true));
}
}
}
ADFUtils的更多相关文章
- adf常用方法总结
1.使用clientAttribute传值.获取值 或组件上面放客户端属性 <af:selectBooleanCheckbox text="" label="&qu ...
- ADF 入门帮助
本文是由英文帮助翻译所得: 1>task flows “任务流 task flows”可以包括非可视化的组件,比如方法调用.“页片段 page fragment”可以运行在一个页面的某个局部区域 ...
- adf笔记
1>jsf页面js调试,手动添加debugger调试 方案:在页面中添加debugger,然后打开“开发者工具”(必须打开),直接运行页面自动跳转到debugger处. 2>jdevelo ...
- AM使用指南:如何在Managed Bean中获取AM实例?
AM是放置服务方法的地方,有时我们需要在Managed Bean中调用这些方法.要调用这些方法,首先要在Managed Bean中获取AM实例.这里要用到<ADF工具类:ADFUtil.java ...
随机推荐
- jqgrid 加载时第一页面只显示多少条数据
function initGrid() { localGrid = jQuery("#tbList"); localGrid.jqGrid({ data: localData, d ...
- mysql 远程连接权限
当你远程连不上时,可能的原因: 1.是否开启了远程连接权限 2.是否启动了mysql服务 使用客户端远程登陆报错: 使用命令行myslq -h192.168.82.23 -uroot -p123456 ...
- centos自带python2.6无法使用pip命令
1.首先检查linux有没有安装python-pip包,直接执行 yum install python-pip,或者 which pip 我的已经安装了 2.没有可用软件包 python-pip.就执 ...
- Java内存溢出定位和解决方案(new)
引起内存溢出的原因有很多种,列举一下常见的有以下几种: 1.内存中加载的数据量过于庞大,如一次从数据库取出过多数据:2.集合类中有对对象的引用,使用完后未清空,使得JVM不能回收:3.代码中存在死循环 ...
- Object.defineProperty使用技巧
Object.definedProperty 该方法允许精确添加或修改对象的属性.通过赋值操作添加的普通属性是可枚举的,能够在属性枚举期间呈现出来(for...in 或 Object.keys 方法) ...
- FLASK日志记录
from flask import Flask from flask_restful import Resource, Api import logging app = Flask(__name__) ...
- vue-router 的使用
vue-router 是 vue 的 一个特色. 下面介绍vue-router 的使用: 一.先将vue-router作为vue 的一个插件使用 import Vue from 'vue' imp ...
- 微信小程序支付返回信息为空
1.昨天公司说要实现微信小程序的支付,于是看了下微信小程序的开发api文档,和之前的app 端以及pc端基本相似:于是让他们把参数改了下,把之前的trade_type 由 app 改成 小程序要求的 ...
- PHP discuz模板语法
Discuz! X 模板的解析主要是 ./source/class/class_template.php 文件解析处理的,如果需要深入了解请可以看看这个文件! 模板嵌套语法 将被嵌套模板内容解析为 P ...
- Linux 学习笔记之关机问题
在linux领域内大多用在服务器上,很少遇到关机的操作. 正确的关机流程为:sync > shutdown > reboot > halt 关机指令为:shutdown ,你可以ma ...