Skip to content

Commit c247d79

Browse files
committed
LinkedHashMap in Drop-Down
1 parent a2f6607 commit c247d79

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Spring MVC/WebContent/WEB-INF/view/student-form.jsp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
<br>
1818
<form:select path="country">
1919

20-
<form:option value="india" label="India"/>
21-
<form:option value="australia" label="Australia"/>
22-
<form:option value="england" label="England"/>
20+
<form:option value="india" label="India JSP"/>
21+
<form:option value="australia" label="Australia JSP"/>
22+
<form:option value="england" label="England JSP"/>
23+
<form:options items="${student.countryOptions}"/>
2324

2425
</form:select>
2526

Binary file not shown.

Spring MVC/src/com/udemy/spring/form/Student.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
11
package com.udemy.spring.form;
22

3+
import java.util.LinkedHashMap;
4+
35
public class Student {
46

57
public String firstname;
68
public String lastname;
79
public String country;
10+
11+
public LinkedHashMap<String,String> countryOptions;
12+
813
public Student()
914
{
15+
countryOptions=new LinkedHashMap<>();
1016

17+
countryOptions.put("IN","India Map");
18+
countryOptions.put("Aus","Australia Map");
19+
countryOptions.put("Eng","England Map");
1120
}
1221

1322
public String getCountry() {
1423
return country;
1524
}
1625

1726
public void setCountry(String country) {
18-
country = country;
27+
this.country = country;
1928
}
2029

2130
public String getFirstname() {
2231
return firstname;
2332
}
2433

34+
public LinkedHashMap<String, String> getCountryOptions() {
35+
return countryOptions;
36+
}
37+
38+
public void setCountryOptions(LinkedHashMap<String, String> countryOptions) {
39+
this.countryOptions = countryOptions;
40+
}
41+
2542
public void setFirstname(String firstname) {
2643
this.firstname = firstname;
2744
}

0 commit comments

Comments
 (0)