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 ...
随机推荐
- 软工网络15Alpha阶段敏捷冲刺博客汇总
博客链接汇总: 第一篇:http://www.cnblogs.com/pubg722/p/8891605.html 第二篇:http://www.cnblogs.com/pubg722/p/89090 ...
- vs2013中$(TargetPath)与Link.OutputFile不同,导致调试debug找不到exe
之前把VS2008项目升级为VS2013项目后,出现了VS2013调试debug找不到exe文件的现象,如:http://blog.sina.com.cn/s/blog_6c617ee301013xt ...
- 问题集录04--json和jsonp讲解
JSON和JSONP JSON(Javascript Object Notation)是一种轻量级的数据交换格式,用于在浏览器和服务器之间交换信息. JSONP(JSON With Padding ...
- telnet 命令使用方法详解
参考自:这里 什么是telnet? 简单来说,可以把telnet当作一种通信协议.但对于入侵者来说,telnet只是一种远程登陆的工具.一旦入侵者与远程主机建立了telnet链接,入侵者便可以使用目标 ...
- .Net程序员玩转Android系列之三~快速上手
快速环境搭建和Hello World 第一步:JAVA SDK(JDK)的安装: 官方下载地址: http://www.oracle.com/technetwork/java/javase/downl ...
- .net EF框架 MySql实现实例
1.nuget中添加包EF和MySql.Data.Entity 2.config文件添加如下配置 1.配置entitframework节点(一般安装EF时自动添加) <entityFramewo ...
- JavaScript数组循环遍历之forEach
1. js 数组循环遍历. 数组循环变量,最先想到的就是 for(var i=0;i<count;i++)这样的方式了. 除此之外,也可以使用较简便的forEach 方式 2. forEac ...
- 设计模式入门,单件模式,c++代码实现
// test05.cpp : Defines the entry point for the console application.// #include "stdafx.h" ...
- lintcode 刷题记录··
单例模式,用C#实现过单例模式,python区别就是类里边的静态方法写法不一样,python叫类方法,函数之前加@classmethod class Solution: # @return: The ...
- Grunt完整打包一个项目实例
Grunt确实好用,配置好Gruntfile.js之后,一个命令就行云如流水,程序帮你搞定一切,爽歪歪. 我们先看压缩前的目录: 再看打包后的目录: build是打包后的文件夹,main.css是压缩 ...