訪問(wèn)數(shù)據(jù)庫(kù)的部分:
/*
? * 獲取所有大類的類別列表
? */
public static Map getAccessoriesBigTypeInfoMap(){
??
??Map map = new HashMap();
??List list = new ArrayList();
??Session session = SessionFactory.currentSession();
??Transaction tx = session.beginTransaction();
??
??try {
???
???list = session.createQuery("from AccessoriesTypeInfo where UPID is null or UPID = 0").list();
???for(int i=0;i<list.size();i++){
????????????
??????//---------這里只能采用這種形式,呵呵,為什么??請(qǐng)去看DWR的文檔吧
????map.put(((AccessoriesTypeInfo)list.get(i)).getId(),((AccessoriesTypeInfo)list.get(i)).getTypename());
???}
???tx.commit();
??} catch (Exception e) {
???log.error("AccessoriesTypeInfoDAO.getAccessoriesBigTypeInfoList() failed!!!"+e.getMessage());
???if(tx != null) tx.rollback();
??}finally{
???if(session != null) session.close();
??}
??return map;
?}
/*
? * 獲取指定大類下的小類類別列表
??*String upid:大類ID
? */
public static Map getAccessoriesSmallTypeInfoMap(String upid){
??
??Map map = new HashMap();
??List list = new ArrayList();
??Session session = SessionFactory.currentSession();
??Transaction tx = session.beginTransaction();
??
??try {
???
???int id = Integer.parseInt(upid);
???list = session.createSQLQuery("select {t.*} from AccessoriesTypeInfo t where t.UPID = ?").addEntity("t",AccessoriesTypeInfo.class).setInteger(0,id).list();
???for(int i=0;i<list.size();i++){
????map.put(((AccessoriesTypeInfo)list.get(i)).getId(),((AccessoriesTypeInfo)list.get(i)).getTypename());
???}
???tx.commit();
??} catch (Exception e) {
???log.error("AccessoriesTypeInfoDAO.getAccessoriesBigTypeInfoList() failed!!!"+e.getMessage());
???if(tx != null) tx.rollback();
??}finally{
???if(session != null) session.close();
??}
??return map;
?}
信息顯示頁(yè):
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.List"%>
<script type='text/javascript' src='/qcbst/dwr/interface/JDate.js'></script>
?<script type='text/javascript' src='/qcbst/dwr/engine.js'></script>
?<script type='text/javascript' src='/qcbst/dwr/util.js'></script>
?<script type='text/javascript' src='/qcbst/dwr/interface/AccessoriesType.js'></script>
<script type="text/javascript" src="../../js/clearspace.js"></script>
<script language="javascript">
?function selectAorigin(o){
??
???? var big = document.getElementById("bigcategories");
?? var small = document.getElementById("smallcategories");
?? big.length=1;
?? small.length=1; ?
?? big.options[0].selected=true;
?? small.options[0].selected=true;
?? if(o == "0"){
??
??DWRUtil.removeAllOptions("bigcategories");?? //----------移除下拉列表中的內(nèi)容
??DWRUtil.removeAllOptions("smallcategories");
??DWRUtil.addOptions("bigcategories",{0:'選擇大類'});//----------設(shè)置一個(gè)初始化的下拉列表內(nèi)容
??DWRUtil.addOptions("smallcategories",{0:'選擇小類'});
?? ? big.length=1;
??? small.length=1; ?
??? big.options[0].selected=true;
??? small.options[0].selected=true;
?? }else{
?????????
??????//-----------將AccessoriesType.getAccessoriesBigTypeInfoMap()取得的信息給getABigInfo()
?? AccessoriesType.getAccessoriesBigTypeInfoMap(getABigInfo);
? }
?}
?function getABigInfo(d){
??
??DWRUtil.addOptions("bigcategories",d);
?}
?
?
?function selectAbigcategories(brand){
?? var small = document.getElementById("smallcategories");
?? small.length=1;
?? small.options[0].selected=true;
? if(brand == "0"){
?
? small.length=1;
?? small.options[0].selected=true;
? }
??AccessoriesType.getAccessoriesSmallTypeInfoMap(getASmallInfo,brand);
?}
?function getASmallInfo(d){
?
??DWRUtil.addOptions("smallcategories",d);
?}
?
?function clearAInfo(){
??document.getElementById("accessoriesname").value="";
?}
?</script>
<form id="form1" name="form1" method="post" action="/qcbst/v_viewaccessoriesinfosearch1" style="0 0 0 0" target="_top">
??????????????? <table width="150" border="0" cellspacing="5" cellpadding="0">
????????????????? <tr>
??????????????????? <td height="30" align="center"><span class="STYLE1">請(qǐng)?jiān)谙逻呥M(jìn)行精確搜索</span></td>
????????????????? </tr>
????????????????? <tr>
??????????????????? <td align="center"><select name="aarea" onChange="selectAorigin(this.value)">
??????????????????????? <option value="0" selected>選擇區(qū)域</option>
??????????????????????? <option value="國(guó)產(chǎn)">國(guó)產(chǎn)</option>
??????????????????????? <OPTION value="進(jìn)口">進(jìn)口</OPTION>
????????????????????? </select>
??????????????????? </td>
????????????????? </tr>
????????????????? <tr>
??????????????????? <td align="center"><select name="bigcategories" onChange="selectAbigcategories(this.value)">
??????????????????????? <option value="0" selected>選擇大類</option>
???????????????????????
????????????????????? </select>
??????????????????? </td>
????????????????? </tr>
????????????????? <tr>
??????????????????? <td align="center"><select name="smallcategories">
??????????????????????? <option value="0" selected>選擇小類</option>
????????????????????? </select>
??????????????????? </td>
????????????????? </tr>
????????????????? <tr>
??????????????????? <td align="center"><input name="accessoriesname" type="text" value="??? 配件名稱" size="15" onFocus="clearAInfo()" /></td>
????????????????? </tr>
????????????????? <tr>
??????????????????? <td align="center"><input type="submit" name="Submit" value="開始精確查找" /></td>
????????????????? </tr>
??????????????? </table>
??????????? </form>
WEB-INF下的DWR.XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "
http://www.getahead.ltd.uk/dwr/dwr10.dtd
">
<dwr>
<allow>
<create creator="new" javascript="AccessoriesType">
<param name="class" value="com.lvke.web.qcbst.dao.automobile.AccessoriesTypeInfoDAO"/>
</create>?
</allow>
</dwr>