2017-10-16 65 views
0

在我的控制器中我已经写了如下填充国家列表和状态列表填充状态下拉(){基于国家下拉的在Java春天选择

List <State> states = stateService.findAllStates(); 

    return states; 

}

而在我的JSP中,我已填充在国家和地区成功状态:

<form:select path="country" id="country"> 
    <form:option value="">Select Country</form:option> 
    <form:options items="${countries}" itemValue="countryCode" itemLabel 
    = "countryName" /> 
</form:select> 
<form:errors path="country" cssClass="error"/> 

<form:select path="state" id="state"> 
    <form:option value="">Select Country</form:option> 
    <form:options items="${states}" itemValue="stateCode" 
    itemLabel="stateName" /> 
</form:select> 
<form:errors path="state" cssClass="error"/> 

但我需要根据国家的选择填充状态。

+0

你必须使用JavaScript来实现这一点。 –

回答

0

您可以使用Ajax和JavaScript/JQuery。这里举一个例子,这可能会帮助你

$("#country").change(function() { 
    var countryId = $(this).val(); 
    $.ajax({ 
     async: true, 
     type: 'GET', 
     url: '/fetchStates', 
     data: { 
      countryId : countryId, 
     }, 
     error: function() { 
      alert("Error"); 
     }, 
     success: function(stateDetails) { 
      // call a function to populate state details 
     } 
    }); 
}); 
+0

没有工作。我使用了以下内容: –

+0

请检查下面的代码并让我知道您的建议 –