package bps.com.cn.tag;
import java.io.IOException;
import java.util.Map;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.IntegerConverter;
public class UISpinner extends UIInput {
private static final String MORE = ".more";
private static final String LESS = ".less";
public UISpinner() {
setConverter(new IntegerConverter());
setRendererType(null);
}
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
String clientId = getClientId(context);
encodeInputField(writer, clientId);
encodeDecrementButton(writer, clientId);
encodeIncrementButton(writer, clientId);
}
public void decode(FacesContext context) {
Map requestMap
= context.getExternalContext().getRequestParameterMap();
String clientId = getClientId(context);
int increment;
if (requestMap.containsKey(clientId + MORE)) increment = 1;
else if(requestMap.containsKey(clientId + LESS)) increment = -1;
else increment = 0;
try {
int submittedValue
= Integer.parseInt((String) requestMap.get(clientId));
int newValue = getIncrementedValue(submittedValue, increment);
setSubmittedValue("" + newValue);
setValid(true);
}
catch(NumberFormatException ex) {
setSubmittedValue((String) requestMap.get(clientId));
}
}
private void encodeInputField(ResponseWriter writer, String clientId)
throws IOException {
writer.startElement("input", this);
writer.writeAttribute("name", clientId, "clientId");
Object v = getValue();
if (v != null)
writer.writeAttribute("value", v.toString(), "value");
Integer size = (Integer)getAttributes().get("size");
if(size != null)
writer.writeAttribute("size", size, "size");
writer.endElement("input");
}
private void encodeDecrementButton(ResponseWriter writer, String clientId)
throws IOException {
writer.startElement("input", this);
writer.writeAttribute("type", "submit", null);
writer.writeAttribute("name", clientId + LESS, null);
writer.writeAttribute("value", "<", "value");
writer.endElement("input");
}
private void encodeIncrementButton(ResponseWriter writer, String clientId)
throws IOException {
writer.startElement("input", this);
writer.writeAttribute("type", "submit", null);
writer.writeAttribute("name", clientId + MORE, null);
writer.writeAttribute("value", ">", "value");
writer.endElement("input");
}
private int getIncrementedValue(int submittedValue, int increment){
Integer minimum = (Integer) getAttributes().get("minimum");
Integer maximum = (Integer) getAttributes().get("maximum");
int newValue = submittedValue + increment;
if ((minimum == null || newValue >= minimum.intValue()) &&
(maximum == null || newValue <= maximum.intValue()))
return newValue;
else
return submittedValue;
}
}
JSF入门实例-用户登录
5星 · 超过95%的资源 需积分: 10 102 浏览量
2010-04-22
17:19:32
上传
评论 1
收藏 14KB RAR 举报
chf1204
- 粉丝: 1
- 资源: 11
最新资源
- [大模型部署]在C# Winform中使用文心一言ERNIE-3.5 4K 聊天模型
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统设计与实现.zip
- python毕业设计-基于Django+OpenCV的二维码生成与识别系统设计与实现+使用说明.zip
- 基于STM32单片机空气监测系统设计源码+详细文档+配套全部资料(毕业设计).zip
- rdf0412-kcu116-pcie-c-2019-1.zip(XILINX KCU116 源码)
- 基于C#语言的winform界面火车票订票系统(源码+实验报告)
- 【华为OD部分真题及讲解】华为OD部分真题及讲解
- 基于Python+Django的京东商品比价系统源码+全部资料(毕业设计).zip
- G460 G560 Z460 Z560的最新BIOS 2.18版(无白名单)
- MetaJUI v0.4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页