jsf中工具函数
来源:互联网 发布:finale 2014 mac 破解 编辑:程序博客网 时间:2024/05/17 02:50
package view.util;
import javax.ejb.SessionBean;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.webapp.UIComponentTag;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import view.asrservice.BeanNames;
import com.sun.faces.config.beans.ApplicationBean;
/**//**
* 应用上下文管理
* @author wjb
* @version 1.0
* @since 2006.4.10
*/
public class FacesUtils
...{
/**//**
* Get servlet context.
* @return the servlet context
* @roseuid 44445BC9007B
*/
public static ServletContext getServletContext()
...{
return (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
}
/**//**
* Get managed bean based on the bean name.
* @param beanName the bean name
* @return the managed bean associated with the bean name
* @roseuid 44445BC9008F
*/
public static Object getManagedBean(String beanName)
...{
Object o = getValueBinding(getJsfEl(beanName)).getValue(FacesContext.getCurrentInstance());
return o;
}
/**//**
* Remove the managed bean based on the bean name.
* @param beanName the bean name of the managed bean to be removed
* @roseuid 44445BC90091
*/
public static void resetManagedBean(String beanName)
...{
getValueBinding(getJsfEl(beanName)).setValue(FacesContext.getCurrentInstance(), null);
}
/**//**
* Store the managed bean inside the session scope.
* @param beanName the name of the managed bean to be stored
* @param managedBean the managed bean to be stored
* @roseuid 44445BC9009A
*/
public static void setManagedBeanInSession(String beanName, Object managedBean)
...{
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(beanName, managedBean);
}
/**//**
* Get parameter value from request scope.
* @param name the name of the parameter
* @return the parameter value
* @roseuid 44445BC900A5
*/
public static String getRequestParameter(String name)
...{
return (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
}
/**//**
* Get <code>ApplicationBean</code>.
* <p>
* Specific for this application.
* @return the application bean
* @roseuid 44445BC900AD
*/
public static ApplicationBean getApplicationBean()
...{
return (ApplicationBean)getManagedBean(BeanNames.APPLICATION_BEAN);
}
/**//**
* Get <code>SessionBean</code>.
* <p>
* Specific for this applicaiton.
* @return the session bean
* @roseuid 44445BC900AE
*/
public static SessionBean getSessionBean()
...{
return (SessionBean)getManagedBean(BeanNames.SESSION_BEAN);
}
/**//**
* Add information message.
* @param msg the information message
* @roseuid 44445BC900C1
*/
public static void addInfoMessage(String msg)
...{
addInfoMessage(null, msg);
}
/**//**
* Add information message to a sepcific client.
* @param clientId the client id
* @param msg the information message
* @roseuid 44445BC900CB
*/
public static void addInfoMessage(String clientId, String msg)
...{
FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg));
}
/**//**
* Add error message.
* @param msg the error message
* @roseuid 44445BC900CE
*/
public static void addErrorMessage(String msg)
...{
addErrorMessage(null, msg);
}
/**//**
* Add error message to a sepcific client.
* @param clientId the client id
* @param msg the error message
* @roseuid 44445BC900D6
*/
public static void addErrorMessage(String clientId, String msg)
...{
FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
}
/**//**
* Evaluate the integer value of a JSF expression.
* @param el the JSF expression
* @return the integer value associated with the JSF expression
* @roseuid 44445BC900E1
*/
public static Integer evalInt(String el)
...{
if (el == null) ...{
return null;
}
if (UIComponentTag.isValueReference(el)) ...{
Object value = getElValue(el);
if (value == null) ...{
return null;
}
else if (value instanceof Integer) ...{
return (Integer)value;
}
else ...{
return new Integer(value.toString());
}
}
else ...{
return new Integer(el);
}
}
/**//**
* @return javax.faces.application.Application
* @roseuid 44445BC900F3
*/
private static Application getApplication()
...{
ApplicationFactory appFactory = (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
return appFactory.getApplication();
}
/**//**
* @param el
* @return javax.faces.el.ValueBinding
* @roseuid 44445BC900FD
*/
private static ValueBinding getValueBinding(String el)
...{
return getApplication().createValueBinding(el);
}
/**//**
* @return javax.servlet.http.HttpServletRequest
* @roseuid 44445BC90108
*/
private static HttpServletRequest getServletRequest()
...{
return (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
}
/**//**
* @param el
* @return java.lang.Object
* @roseuid 44445BC90125
*/
private static Object getElValue(String el)
...{
return getValueBinding(el).getValue(FacesContext.getCurrentInstance());
}
/**//**
* @param value
* @return java.lang.String
* @roseuid 44445BC90130
*/
private static String getJsfEl(String value)
...{
return "#{" + value + "}";
}
}
- jsf中工具函数
- JSF测试工具
- JSF中调用js函数方法之一和二
- JSF中使用Tiles
- jsf学习中
- JSF中类简介
- ADF 中 jsf jspx
- JSF中使用CSS
- JSF中使用jquery
- JSF中使用UEditor
- 关于jquery中工具函数
- JBOSS发布JSF测试工具-JSFUnit
- JSF中生成自定义标签
- 在JSF中整合Spring
- JSF中控件赋值方式
- jsf 中 ViewExpiredException 的处理
- 在JSF中实现分页
- NetBeans中JSF应用开发
- 内存泄漏。。。
- DAEMON Tools v4.03HE [for both X64 and X86(32bit)]
- 在.net中访问硬盘中的.text文件,并用于滚动显示
- 一个老程序员的心里话 zz
- 如何获得客户端的ip地址
- jsf中工具函数
- Steganography v1.8
- 在 Oracle JDBC 访问中加入一些 Spring 特性
- 转换 xml 格式,默认 utf-8 , 要输出成 gbk ,并保存 (java )
- SQL-SERVER 声明游标
- java操作FTP
- 对XML文件的基本操作
- .net中几个经常用到的字符串的截取
- 我的历史观:汉代风云-2006年8月31