[英]How to display only selected list of items?
I am trying to populate a list something like below:我正在尝试填充如下所示的列表:
<select name="prescription" multiple="multiple">
<c:forEach items="${medicines}" var="current">
<option value="${current}"><c:out value="${current}" /></option>
</c:forEach>
</select>
I am trying to populate only the selected list in another similar for each loop.我试图在每个循环的另一个类似中只填充选定的列表。 But i am not getting how to do it.
但我不知道该怎么做。 Can any one help me with it?
任何人都可以帮助我吗?
Seems like you are showing some list from the controller to the jsp page , You can proceed with either of these 2 ways似乎您正在显示从控制器到 jsp 页面的一些列表,您可以使用这两种方式之一
assuming that the list medicine has all the parameters假设列表药物具有所有参数
List<String> medicine = Your-List;
List<String> final_medicine = new ArrayList<String>();
for(int i=0; i < medicine.size(); i++)
{
if(your-condition-here){
final_medicine.add(medicine.get(i));
}
}
request.setAttribute("medicine",final_medicine);
The second way could be getting the values in the jsp itself using the第二种方法可能是使用
<select name="prescription" multiple="multiple">
<c:forEach items="${medicines}" var="current">
<c:if test="${medicines eq your-condition}>
<option value="${current}"><c:out value="${current}" /></option>
</c:if>
</c:forEach>
</select>
If this is something that you require?如果这是您需要的东西?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.