📄 tagutil.java
字号:
package com.cim.jsf.util;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
import javax.faces.webapp.UIComponentTag;
public class TagUtil {
public static void setObject( UIComponent component, String attributeName,
String attributeValue ) {
if ( attributeValue == null ) {
return;
}
if ( UIComponentTag.isValueReference( attributeValue ) ) {
setValueBinding( component, attributeName, attributeValue );
} else {
component.getAttributes().put( attributeName, attributeValue );
}
}
public static void setString( UIComponent component, String attributeName,
String attributeValue ) {
if ( attributeValue == null ) {
return;
}
if ( UIComponentTag.isValueReference( attributeValue ) ) {
setValueBinding( component, attributeName, attributeValue );
} else {
component.getAttributes().put( attributeName, attributeValue );
}
}
public static void setInteger( UIComponent component, String attributeName,
String attributeValue ) {
if ( attributeValue == null ) {
return;
}
if ( UIComponentTag.isValueReference( attributeValue ) ) {
setValueBinding( component, attributeName, attributeValue );
} else {
component.getAttributes().put( attributeName,
new Integer( attributeValue ) );
}
}
public static void setBoolean( UIComponent component, String attributeName,
String attributeValue ) {
if ( attributeValue == null ) {
return;
}
if ( UIComponentTag.isValueReference( attributeValue ) ) {
setValueBinding( component, attributeName, attributeValue );
} else {
component.getAttributes().put( attributeName,
new Boolean( attributeValue ) );
}
}
public static void setValueBinding( UIComponent component,
String attributeName,
String attributeValue ) {
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
ValueBinding vb = app.createValueBinding( attributeValue );
component.setValueBinding( attributeName, vb );
}
public static void setMethodBinding( UIComponent component,
String attributeName,
String attributeValue,
Class[] paramTypes ) {
if ( attributeValue == null ) {
return;
}
if ( UIComponentTag.isValueReference( attributeValue ) ) {
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
MethodBinding mb = app.createMethodBinding( attributeValue,
paramTypes );
component.getAttributes().put( attributeName, mb );
}
}
public static Object evaluateVBExpression( String expression ) {
if ( expression == null ) {
return expression;
}
if ( !UIComponentTag.isValueReference( expression ) ) {
return expression;
}
FacesContext context = FacesContext.getCurrentInstance();
Object result = context.getApplication().createValueBinding( expression ).
getValue( context );
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -