我的Blog我做主^_^

走向一条通往JAVA的不归路...

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  64 随笔 :: 68 文章 :: 77 评论 :: 0 Trackbacks


访问数据库的部分:


/*
  * 获取所有大类的类别列表
  */

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++){
            
      //---------这里只能采用这种形式,呵呵,为什么??请去看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;
 }


信息显示页:


<%@ 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");   //----------移除下拉列表中的内容
  DWRUtil.removeAllOptions("smallcategories");
  DWRUtil.addOptions("bigcategories",{0:'选择大类'});//----------设置一个初始化的下拉列表内容
  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">请在下边进行精确搜索</span></td>
                  </tr>
                  <tr>
                    <td align="center"><select name="aarea" onChange="selectAorigin(this.value)">
                        <option value="0" selected>选择区域</option>
                        <option value="国产">国产</option>
                        <OPTION value="进口">进口</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>



posted on 2006-12-28 18:48 java_蝈蝈 阅读(2069) 评论(0)  编辑  收藏 所属分类: OPEN SOURCE

只有注册用户登录后才能发表评论。


网站导航: