依赖选择一个在另一个上

时间:2013-02-15 06:06:28

标签: html jsp jstl

早上好, 我有一段看起来很重的代码,我想用光代码。我的任务是使用两个下拉框选择州和城市。我需要更改关于状态下拉框的城市下拉框,帮助我这个

这里我的代码:::

<fieldset>
    <legend>Compare To</legend>
    <span>state</span><select id="locationId" name="locationId">
    <option value="0" <c:if test="${loc.location eq '0'}">selected="selected"</c:if>>All Locations</option> 
    <c:forEach items="${locationDetailsList}" var="locationDetails">
        <option value="${locationDetails.locationId}" <c:if test="${loc.locationId2 eq locationDetails.locationId}">
        selected="selected"</c:if>>${locationDetails.locationName}</option>
    </c:forEach></select>

    <span>area</span> 
    <select id="area" name="area">
        <option value="0" <c:if test="${locationId eq '0'}">selected="selected"</c:if>>All Locations</option> 
        <option value="1" <c:if test="${locationId ge '1'}">selected="selected"</c:if>>Hyderabad</option>
        <option value="1" <c:if test="${locationId ge '1'}">selected="selected"</c:if>>Vizag</option>
    </select> 
</fieldset> 
提前亲爱的朋友......

1 个答案:

答案 0 :(得分:0)

从这个问题的答案:JSTL in JSF2 Facelets... makes sense? JSTL标签(...)在视图构建时执行,这意味着它们只被评估一次在构建要呈现给客户端的HTML时。

了解这一点,您只能通过对服务器执行完整请求/响应来更新<select id="area">中的数据,以根据<select id="locationId">组件的值加载值。

在这种情况下,让用户只使用下拉列表的元素获得全新的响应是非常痛苦的,因此您可以使用如下所示的Ajax方法:How to use Servlets and Ajax?请注意,BalusC甚至会写一个完整的示例关于根据中的<option>构建Map<String, String>列表这是另一个将Map<String, String>显示为<option> 部分的示例。

请记住,对于ajax解决方案,您的<select id="area">内部不应包含任何JSTL标记,它根本不应包含任何元素:

<select id="area">
</select>
相关问题