jsf自定义组件-jafyear选择年份
来源:互联网 发布:域名服务器 级联 编辑:程序博客网 时间:2024/05/15 23:53
就是一个下拉框,可以配置选取的范围,用today表示当期年份,输入简单表达式。
package com.cfcc.jaf.webx.component.jafdate.jafyear;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
/** *//**
* 年份选择框组件
* @author qinjinwei
* $date 2007-9-12 上午09:52:28
*/
public class JafYear extends UIComponentBase ...{
public final String JAF_DATE_FAMILY = "jaf.jafdate";
public String getFamily() ...{
return JAF_DATE_FAMILY;
}
public Object saveState(FacesContext context) ...{
Object values[] = new Object[1];
values[0] = super.saveState(context);
return values;
}
public void restoreState(FacesContext context, Object state) ...{
Object values[] = (Object[]) state;
super.restoreState(context, values[0]);
}
}
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
/** *//**
* 年份选择框组件
* @author qinjinwei
* $date 2007-9-12 上午09:52:28
*/
public class JafYear extends UIComponentBase ...{
public final String JAF_DATE_FAMILY = "jaf.jafdate";
public String getFamily() ...{
return JAF_DATE_FAMILY;
}
public Object saveState(FacesContext context) ...{
Object values[] = new Object[1];
values[0] = super.saveState(context);
return values;
}
public void restoreState(FacesContext context, Object state) ...{
Object values[] = (Object[]) state;
super.restoreState(context, values[0]);
}
}
package com.cfcc.jaf.webx.component.jafdate.jafyear;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.el.ValueBinding;
import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
/** *//**
* 年份选择框组件renderer
* @author qinjinwei
* $date 2007-9-12 上午09:52:30
*/
public class JafYearRenderer extends HtmlRenderer ...{
public void encodeEnd(FacesContext facesContext, UIComponent component)
throws IOException ...{
String sfrom = (String) component.getAttributes().get("from");
String sto = (String) component.getAttributes().get("to");
int ifrom = convert(sfrom) + 1900;
int ito = convert(sto) + 1900;
ResponseWriter writer = facesContext.getResponseWriter();
String clientId = component.getClientId(facesContext);
ValueBinding vb = component.getValueBinding("value");
String syear = (String) vb.getValue(facesContext);
if(syear == null)
...{
syear = "" + (new Date().getYear() + 1900 );
}
int year = Integer.parseInt(syear);
writer.write("");
}
public void decode(FacesContext facesContext, UIComponent uiComponent)
...{
Map paramMap = facesContext.getExternalContext()
.getRequestParameterMap();
String clientId = uiComponent.getClientId(facesContext);
if(paramMap.containsKey(clientId))
...{
String value = (String) paramMap
.get(clientId);
ValueBinding vb = uiComponent.getValueBinding("value");
vb.setValue(facesContext, value);
System.out.println(clientId + " value is: " + value);
}
}
private int convert(String exp) ...{
boolean bflagt = false;
boolean bflags = false;
String ex = exp.replaceAll(" ", "");
if (ex.startsWith("today")) ...{
bflagt = true;
ex = ex.replaceAll("today", "");
}
if (ex.startsWith("+")) ...{
bflags = true;
}
ex = ex.substring(1, ex.length());
int rvalue = Integer.parseInt(ex);
if(!bflags)
...{
rvalue = - rvalue;
}
if (bflagt)
rvalue = rvalue + new Date().getYear();
return rvalue;
}
}
import java.io.IOException;
import java.util.Date;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.el.ValueBinding;
import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
/** *//**
* 年份选择框组件renderer
* @author qinjinwei
* $date 2007-9-12 上午09:52:30
*/
public class JafYearRenderer extends HtmlRenderer ...{
public void encodeEnd(FacesContext facesContext, UIComponent component)
throws IOException ...{
String sfrom = (String) component.getAttributes().get("from");
String sto = (String) component.getAttributes().get("to");
int ifrom = convert(sfrom) + 1900;
int ito = convert(sto) + 1900;
ResponseWriter writer = facesContext.getResponseWriter();
String clientId = component.getClientId(facesContext);
ValueBinding vb = component.getValueBinding("value");
String syear = (String) vb.getValue(facesContext);
if(syear == null)
...{
syear = "" + (new Date().getYear() + 1900 );
}
int year = Integer.parseInt(syear);
writer.write("");
}
public void decode(FacesContext facesContext, UIComponent uiComponent)
...{
Map paramMap = facesContext.getExternalContext()
.getRequestParameterMap();
String clientId = uiComponent.getClientId(facesContext);
if(paramMap.containsKey(clientId))
...{
String value = (String) paramMap
.get(clientId);
ValueBinding vb = uiComponent.getValueBinding("value");
vb.setValue(facesContext, value);
System.out.println(clientId + " value is: " + value);
}
}
private int convert(String exp) ...{
boolean bflagt = false;
boolean bflags = false;
String ex = exp.replaceAll(" ", "");
if (ex.startsWith("today")) ...{
bflagt = true;
ex = ex.replaceAll("today", "");
}
if (ex.startsWith("+")) ...{
bflags = true;
}
ex = ex.substring(1, ex.length());
int rvalue = Integer.parseInt(ex);
if(!bflags)
...{
rvalue = - rvalue;
}
if (bflagt)
rvalue = rvalue + new Date().getYear();
return rvalue;
}
}
package com.cfcc.jaf.webx.component.jafdate.jafyear;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.webapp.UIComponentTag;
/** *//**
* 年份选择框组件的标签
* @author qinjinwei
* $date 2007-9-12 上午09:52:36
*/
public class JafYearTag extends UIComponentTag
...{
public String getComponentType()
...{
return "com.cfcc.jaf.webx.component.jafdate.jafyear.JafYear";
}
public String getRendererType()
...{
return "com.cfcc.jaf.webx.component.jafdate.jafyear.JafYearRenderer";
}
private String from;
private String to;
private String value;
public String getValue() ...{
return value;
}
public void setValue(String value) ...{
this.value = value;
}
public String getFrom() ...{
return from;
}
public void setFrom(String from) ...{
this.from = from;
}
public String getTo() ...{
return to;
}
public void setTo(String to) ...{
this.to = to;
}
public void setProperties(UIComponent component) ...{
super.setProperties(component);
setStringProperty(component, "from", from);
setStringProperty(component, "to", to);
setStringProperty(component, "value", value);
}
private void setStringProperty(UIComponent component, String attrName,
String attrValue) ...{
if (attrValue == null)
return;
if (isValueReference(attrValue)) ...{
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
ValueBinding binding = application.createValueBinding(attrValue);
component.setValueBinding(attrName, binding);
} else ...{
component.getAttributes().put(attrName, attrValue);
}
}
public void release() ...{
super.release();
from = null;
to = null;
value = null;
}
}
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.webapp.UIComponentTag;
/** *//**
* 年份选择框组件的标签
* @author qinjinwei
* $date 2007-9-12 上午09:52:36
*/
public class JafYearTag extends UIComponentTag
...{
public String getComponentType()
...{
return "com.cfcc.jaf.webx.component.jafdate.jafyear.JafYear";
}
public String getRendererType()
...{
return "com.cfcc.jaf.webx.component.jafdate.jafyear.JafYearRenderer";
}
private String from;
private String to;
private String value;
public String getValue() ...{
return value;
}
public void setValue(String value) ...{
this.value = value;
}
public String getFrom() ...{
return from;
}
public void setFrom(String from) ...{
this.from = from;
}
public String getTo() ...{
return to;
}
public void setTo(String to) ...{
this.to = to;
}
public void setProperties(UIComponent component) ...{
super.setProperties(component);
setStringProperty(component, "from", from);
setStringProperty(component, "to", to);
setStringProperty(component, "value", value);
}
private void setStringProperty(UIComponent component, String attrName,
String attrValue) ...{
if (attrValue == null)
return;
if (isValueReference(attrValue)) ...{
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
ValueBinding binding = application.createValueBinding(attrValue);
component.setValueBinding(attrName, binding);
} else ...{
component.getAttributes().put(attrName, attrValue);
}
}
public void release() ...{
super.release();
from = null;
to = null;
value = null;
}
}
<tag>
<name>jafyearname>
<tag-class>
com.cfcc.jaf.webx.component.jafdate.jafyear.JafYearTag
tag-class>
<body-content>emptybody-content>
<attribute>
<name>fromname>
<required>truerequired>
attribute>
<attribute>
<name>toname>
<required>truerequired>
attribute>
<attribute>
<name>valuename>
<required>truerequired>
attribute>
tag>
<name>jafyearname>
<tag-class>
com.cfcc.jaf.webx.component.jafdate.jafyear.JafYearTag
tag-class>
<body-content>emptybody-content>
<attribute>
<name>fromname>
<required>truerequired>
attribute>
<attribute>
<name>toname>
<required>truerequired>
attribute>
<attribute>
<name>valuename>
<required>truerequired>
attribute>
tag>
<renderer>
<component-family>jaf.jafdatecomponent-family>
<renderer-type>com.cfcc.jaf.webx.component.jafdate.jafyear.JafYearRendererrenderer-type>
<renderer-class>com.cfcc.jaf.webx.component.jafdate.jafyear.JafYearRendererrenderer-class>
renderer>
<component>
<component-type>
com.cfcc.jaf.webx.component.jafdate.jafyear.JafYear
component-type>
<component-class>
com.cfcc.jaf.webx.component.jafdate.jafyear.JafYear
component-class>
component>
<component-family>jaf.jafdatecomponent-family>
<renderer-type>com.cfcc.jaf.webx.component.jafdate.jafyear.JafYearRendererrenderer-type>
<renderer-class>com.cfcc.jaf.webx.component.jafdate.jafyear.JafYearRendererrenderer-class>
renderer>
<component>
<component-type>
com.cfcc.jaf.webx.component.jafdate.jafyear.JafYear
component-type>
<component-class>
com.cfcc.jaf.webx.component.jafdate.jafyear.JafYear
component-class>
component>
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- jsf自定义组件-jafyear选择年份
- 怎样让.Net2.0的Membership使用已存在的Sql Server2000/2005数据库
- 用VisualC#动态生成组件
- Delphi----永不消逝的精灵
- .jar被winrar关联,轻松修改
- 另類的Silverlight中文解法
- jsf自定义组件-jafyear选择年份
- GlassFish FAQ
- 另類的Silverlight中文解法
- 服装ERP案例:道讯科技协力森马集团ERP升级到小型机
- .NET Framework 3.0框架慨述
- jsf自定义toolbar组件
- 另類的Silverlight中文解法
- GlassFish FAQ
- SQL Server 2005豪华盛宴