In the same context i have another query
<select multiple="multiple" name="prodSKUs">
<c:forEach items="${productSubCategoryList}" var="productSubCategoryList">
<option value="${productSubCategoryList}"${productSubCategoryList == productSubCategoryName ? 'selected' : ''}>${productSubCategoryList}</option>
</c:forEach>
</select>
and the corresponding setting in request is like
for(int i=0;i<userProductData.size();i++){
String productSubCategoryName=userProductData.get(i).getProductSubCategory();
System.out.println(productSubCategoryName);
request.setAttribute("productSubCategoryName",productSubCategoryName);
}
here i have multiple select drop down ,even though i get the return value from for as two ,in the UI only one data is getting higlighted not the second one,What is wrong in the code ?
Assuming that you have a collection ${roles} of the elements to put in the combo, and ${selected} the selected element, It would go like this:
UPDATE (next question)
You are overwriting the attribute "productSubCategoryName". At the end of the for loop, the last productSubCategoryName.
Because of the limitations of the expression language, I think the best way to deal with this is to use a map:
And then in the JSP:
In Servlet do:
Then in JSP do:
It will print the
selected
attribute of the HTML<option>
element so that you end up like:Apart from the problem: this is not a combo box. This is a dropdown. A combo box is an editable dropdown.
Real simple. You just need to have the string 'selected' added to the right option. In the following code, ${myBean.foo == val ? 'selected' : ' '} will add the string 'selected' if the option's value is the same as the bean value;