获得下拉列表值与el

时间:2012-07-11 12:05:57

标签: jsp java-ee el

我现在看起来像是一个解决方案的5个小时,它应该是简单的,但我只是不明白。

我有一个下拉列表,其中填充了我的数据库中的值,现在我想获取此下拉列表中的selectet项目,并使用EL将其设置为java变量。

编辑:下拉列表工作正常。我需要的是获取当前的选择值并将其保存到java变量

这是我对标签的尝试,但它无法正常工作

 <select id="dep" name="dep">
                        <c:forEach items="#{departmentBean.depList}" var="item">  
                            <c:set var="#{courseOfStudiesBean.depName}" value="#{item.name}" />
                            <option value="#{item.name}" >#{item.name}</option>  
                        </c:forEach> 
                    </select>

2 个答案:

答案 0 :(得分:0)

您必须使用$(立即评估)而不是#(延期评估)。

<select id="dep" name="dep">
  <c:forEach items="${departmentBean.depList}" var="item">  
      <option value="${item.name}" >${item.name}</option>  
  </c:forEach> 
</select>

您可以通过${param}集合在JSP中收到表单提交数据。

<c:if test="${not empty param.dep}">
  <c:out value="${param.dep}"/>
  <c:set var="selection" value="${param.dep}" scope="session"/>
</c:if>

答案 1 :(得分:0)

我解决了它

<h:selectOneMenu id="dep" value="#{courseOfStudiesBean.depName}">
                 <f:selectItems value="${courseOfStudiesBean.departmentValues}"/>
</h:selectOneMenu>
相关问题