2015-12-22 88 views
0

我正在使用Spring MVC并将县列表设置为请求。 我将列表设置为页面请求,但“选定”选项在HTML页面上未突出显示。选择下拉“选定”选项不会突出显示

我的控制器代码如下:

//Populate drop down selection with list of counties ArrayList<County> counties = countyInformation.getCounties(State, Zip); request.setAttribute("counties", counties);

我的JSP代码如下:

<form:select class="form-control" path="counties"> 
     <form:option value="Select County"></form:option> 
     <form:options items="${countiesList}" itemValue="countyFipsId" itemLabel="countyName" /> 
</form:select> 

我也试过这样:

<select id="county" name="county"> 
    <option value="">Select County</option> 
    <c:forEach items="${counties}" var="county"> 

        <c:choose> 
         <c:when test="${county == selectedCountyId}"> 
          <option value="${county.countyId}" selected="selected">${county.countyName}</option> 
         </c:when> 
         <c:otherwise> 
          <option value="${county.countyId}" >${county.countyName}</option> 
         </c:otherwise> 
        </c:choose> 

       </c:forEach> 
      </select> 

是否有任何Spring/Browser渲染中的错误? 当前,所选选项显示在开发工具栏中,但选项本身未突出显示。 It doesn't come into focus on the page

有没有一个jQuery/JavaScript等效的解决方案呢? 任何帮助非常感谢。谢谢

回答

0

你在控制器属性设置为"counties",但你的form:options items设置为${countiesList}。尝试将其更改为${counties}

您可能还想尝试将form:select块封装在spring:bind标记中。

<spring:bind path="controllerName.counties"> 
    <form:select class="form-control" path="controllerName.counties"> 
     <form:option value="Select County"></form:option> 
     <form:options items="${counties}" itemValue="countyFipsId" itemLabel="countyName" /> 
    </form:select> 
</spring:bind> 

编辑:在再次阅读您的文章后,我不确定我的解决方案是否是您之后。您是否正在寻找浏览器来识别从下拉列表中选择的选定列表项目?如果是这样的话,你必须通过javascript添加一个onClick()处理程序来处理请求。直到某种显式动作发生(如js函数,帖子或get)时,才会识别所选项目。

+0

是的,我注意到了错误。写下来时我的错误。但是这个解决方案不起作用。我也尝试过使用,没有运气。 – Guru

+0

如果你可以点击我的问题中提到的图片,你会明白。基本上我希望所选项目在页面加载时突出显示。下拉选项中的选定项目未在HTML页面中突出显示。而且我无法从控制器端控制它。有没有onPageLoad JS等效解决方案? – Guru

+0

您是否为所选项目设置了会话属性? – QuestionMarks

相关问题