Web中下拉框的实现
?
???? 在一项Web工程中,必须要解决,并且要解决好的问题有有下面的几个。1,翻页功能。 2,下拉框(就是要从数据库中将数据以下拉框的形式表现出来)?。 3,(擦,写到这儿忽然忘了第三个是啥了,先放着)。 以前做了一些翻页的功能,所以在这儿就写一下项目中下拉框的实现。
?
???????【下面的内容十分的不成熟,不推荐学习】----JavaEye论坛
?
????? 1,首先在数据库中建立了一张数据库的表格。(?PUB_CERTIFICATETYPE? )
?????????? 在这张数据库的表格中,将 选项 与ID 想对应。即,ID 为 1,2,3,4,5 时,选项 为:身份证,护照,军官证,出生证,护照。?? ID 与选项(或者称为 数据 )一一对应。 ?
?
?????? 2,编写一个PubFactory
?
package org.common.data;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import org.common.component.rcp.interfaces.IPublicProperty;import org.common.dao.hibernate.GenericDAO;import org.common.pub.domain.ComboObject;import org.common.pub.service.IPublicPropertyService;import org.hibernate.SessionFactory;import cn.com.hrs.pub.domain.PubCompany;/** * * 类功能描述:<br> * <ul> * <li>类功能描述1<br> * <li>类功能描述2<br> * <li>类功能描述3<br> * </ul> * 修改记录:<br> * <ul> * <li>修改记录描述1<br> * <li>修改记录描述2<br> * <li>修改记录描述3<br> * </ul> * @author chentiedong * @version 5.0 since Jul 3, 2010 */public class PubDataFactory {private IPublicPropertyService publicPropertyService; private IPublicProperty entityClass;private SessionFactory sessionFactory;//private static PubDataFactory instance;private static HashMap<String, List<IPublicProperty>> rsultHashMap;privateGenericDAO<IPublicProperty, Long> dao;private PubDataFactory(SessionFactory sessionFactory){this.sessionFactory = sessionFactory;HashMap<String, String> conditionHashMap = new HashMap<String, String>();//证件类型列表conditionHashMap.put("iccardtypeList", "select new ComboObject(o.id,o.certificateTypeName) from PubCertificateType as o");//获取结果 rsultHashMap = findComboList(conditionHashMap); //异常 未见异常 IPublicProperty combodataException = new ComboObject("异常","异常"); IPublicProperty combodataNoException = new ComboObject("未见异常","未见异常"); List<IPublicProperty> combodataExceptionList = new ArrayList<IPublicProperty>(); combodataExceptionList.add(combodataException); combodataExceptionList.add(combodataNoException); rsultHashMap.put("exception", combodataExceptionList); //有无 IPublicProperty combodatayes = new ComboObject("有","有"); IPublicProperty combodatano = new ComboObject("无","无"); List<IPublicProperty> combodatayesOrNoList = new ArrayList<IPublicProperty>(); combodatayesOrNoList.add(combodatayes); combodatayesOrNoList.add(combodatano); rsultHashMap.put("youwu", combodatayesOrNoList);}public HashMap<String, List<IPublicProperty>> findComboList(HashMap<String, String> conditionHashMap) {// TODO Auto-generated method stubHashMap<String, List<IPublicProperty>> resultHashMap=new HashMap<String, List<IPublicProperty>>();List<IPublicProperty> publicPropertyList;Object[] values=null; entityClass=new PubCompany(); //临时定义,后边转化为 IPublicProperty 类型 针对选择下拉框dao = new GenericDAO<IPublicProperty, Long>((Class<IPublicProperty>) entityClass.getClass(),sessionFactory); for(Iterator it = conditionHashMap.entrySet().iterator(); it.hasNext(); ){ Map.Entry<String, String> e = (Map.Entry<String, String>)it.next(); publicPropertyList=dao.find(e.getValue(), values); resultHashMap.put(e.getKey(),publicPropertyList ); }return resultHashMap;}public static void getDataListTest(){System.out.println("rsultHashMap:------"+rsultHashMap);}public static String getRecordDisplayName(String dataKey, String recordKey){String result = "";if(rsultHashMap.get(dataKey)!= null){List<IPublicProperty> dataList = rsultHashMap.get(dataKey);for(IPublicProperty record : dataList){if(record.getComboId().equals(recordKey)){result = record.getComboName();}}}return result;}/** * 根据key值 获取数据 * @param dataKey * @return */public static List<IPublicProperty> getData(String dataKey){if(rsultHashMap.get(dataKey)!= null){return rsultHashMap.get(dataKey);}return null;}public static HashMap<String, List<IPublicProperty>> getRsultHashMap() {return rsultHashMap;}}
?
?
???? 上面的程序的作用是:刚刚跳转到jsp界面的时候,将数据库中的数据全部读取出来,然后放在内存之中,这样就能大大提高效率。
?
????? 因为在数据库中的 选项 和 ID 是一一向对应的,所以在数据库中添
?
?