0

I have list of string which i have add in a Custom map

The CustomMap class is a kind of custom map which I am using as utility class to refer the key and value

Example
List<CustomMap<Integer,String>> dropdown=new Arraylist<CustomMap<Integer,String>>;
map.put(1,"APPLE");
map.put(2,"BANANA");
map.put(2,"ORANGE");
map.put(2,"apple");

session.setAttribute("dropdown", dropdown);

In my jsp

<select name="fruit" id="fruit" class="selectBox">
                        <c:forEach var="dropdown" items="${dropdown}">
                            <c:choose>
                                <option value="${dropdown.key}" selected>${dropdown.value}</option>

I am able to list down all the values in dropdown which look like below

APPLE
BANNANA
ORANGE
apple

Now I want to add a sub category which should look like below

APPLE
  ---apple
BANNANA
ORANGE

How could I achieve the subcategory? After selecting the value I am sending the key value back to controller for further proceessing.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Subham
  • 420
  • 3
  • 11
  • 34

1 Answers1

1

You can accomplish anything that is possible in HTML. JSP just allows you to use logic to do so. How would you accomplish this in HTML? Do you just want to indent the subcategory? Indenting the description in the drop down is definitely possible. A lot of time people will use two drop downs for subcategories. The second drop down is populated after the first one is chosen. There is also the possibility of using the optgroup tag. Here is an example

<select>
  <optgroup label="Swedish Cars">
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
      <option value="mercedes">Mercedes</option>
      <option value="audi">Audi</option>
  </optgroup>
</select>

http://www.w3schools.com/tags/tag_optgroup.asp

javaMoca
  • 175
  • 7