2011-03-23 77 views
1

我有那裏的組合列表。國家,州和城市。我需要根據以前的combolist更改列表,如果我更改了國家我需要獲得該國家的相應狀態列表,並且如果我選擇狀態,那麼該州的相應城市。任何人都可以請幫我找到答案。由於3依賴下拉使用struts和休眠(國家,州,市)

public String getStateNCityList() { 
    logger.info("Enter getStateNCityList"); 
    try { 
     AddressUtils addrUtil = new AddressUtils(); 
     this.stateList = addrUtil.getStateList(this.getCountryId()); 
     this.cityList = addrUtil.getCityList(this.getStateList().get(0).getAddressComboId()); 
     this.session.put("stateList", this.stateList); 
     this.session.put("cityList", this.cityList); 
     System.out.println("state list size "+this.stateList.size()); 
     System.out.println("city list size "+this.cityList.size()); 
    } catch(Exception e) { 
     logger.error(e,e); 
     return ERROR; 
    } 
    logger.info("Exit getStateNCityList"); 
    return SUCCESS; 
} 

//addressUtils.java

public List<AddressComboDetails> getCountryList(){ 
    List<AddressComboDetails> countryList = new ArrayList<AddressComboDetails>(); 
    try{ 
    String query=" addressComboTypeId="+ApplicationConstants.COMBO_COUNTRY; 
    countryList=addressDao.getAddressComboDetailsByWhereClause(query); 
    System.out.println("countryList size" +countryList.size()); 
    } catch(Exception e) { 
     logger.error("Exception in getCountryList"); 
     logger.error(e,e); 
    } 
    return countryList; 
} 

//冬眠Java類

public List<AddressComboDetails> getAddressComboDetailsByWhereClause(
     String whereClause) { 
    logger.info("entered getAddresscomboDetailsByWhereClause "); 
    List<AddressComboDetails> addressComboList = new ArrayList<AddressComboDetails>(); 
    Session session = null; 

    try { 
     session = HibernateUtil.getSession(); 
     Transaction tx = session.beginTransaction(); 
     String query = " from AddressComboDetails where " + whereClause; 
     System.out.println("Query is "+query); 
     addressComboList = (List<AddressComboDetails>) session.createQuery(query).list(); 
     tx.commit(); 

    } catch (HibernateException e) { 
     logger.error("error in getAddresscomboDetailsByWhereClause"+ e.getMessage()); 
     logger.error(e,e); 
    } finally { 
     session.close(); 
    } 
    return addressComboList; 
} 

//我的jsp頁面代碼

<tr> 
       <td class="generalText"><s:text name="country" /></td> 
       <td><s:select listValue="addressComboValue" listKey="addressComboId" list="#session.countryList" onchange="dojo.event.topic.publish('address_country_details');return false;" 
        name="corpAddress.country.addressComboId" /> 
        <s:set name="countryId" value="%{corpAddress.country.addressComboId}" /></td> 
        <td><s:url id="corp_country" action="getStateNCityList.action" > 
        <s:param name="countryId" value="%{11}"></s:param></s:url> 
        <sx:div id="country" cssStyle="display:none;" href="%{corp_country}" listenTopics="address_country_details" formId="supplierDetails" showLoadingText=""></sx:div> 
      </tr> 

回答

0

添加一個 '變' JavaScript國家組合的事件監聽器,它將使用AJAX l填寫所選國家的州名單,並更改州組合的選項。爲了加載城市,對狀態組合也要做同樣的事情。

AJAX調用可以調用返回HTML選項列表或JSON狀態/城市數組的列表操作。 struts動作應該使用Hibernate查詢來查找數據庫中某個國家(或某個州的城市)的狀態。

+0

@ JB Nizet:我嘗試了一切,但我無法顯示列表。我也獲得了大小。我正在使用dojo發佈並調用該操作。如果你有任何代碼或者其他東西,那麼請讓我知道。這將是非常友善的。感謝回覆 – Ani 2011-03-23 14:37:24

+0

@Ani:告訴我們你遇到問題的代碼,告訴我們你期待什麼,取而代之的是什麼。我們願意提供幫助,但不會爲您實施所有應用。 – 2011-03-23 14:44:10

+0

@JB Nizet:我已經更新了我的代碼。可以請我爲我的問題找到解決方案。我無法在jsp頁面中彈出列表數據。但是我可以從數據庫中正確地獲取列表。我正在使用pgsql。 – Ani 2011-03-23 14:56:20

相關問題