Created
October 10, 2016 18:40
-
-
Save jpukg/eb7278d74088db67a41bba6a5f31b4ad to your computer and use it in GitHub Desktop.
Spring MVC radiobutton example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Database table name is employees | |
| * column name is gender_status | |
| * data type is nvarchar(1) | |
| * | |
| */ | |
| /* | |
| * Employee.java | |
| * | |
| */ | |
| @Entity | |
| @Table(name = "employees") | |
| public class Employee { | |
| public enum GenderStatus { | |
| M("M", "MALE"), F("F", "FEMALE"); | |
| private String code; | |
| private String description; | |
| private GenderStatus() { | |
| } | |
| private GenderStatus(String code, String description) { | |
| this.code = code; | |
| this.description = description; | |
| } | |
| public String getCode() { | |
| return code; | |
| } | |
| public void setCode(String code) { | |
| this.code = code; | |
| } | |
| public String getDescription() { | |
| return description; | |
| } | |
| public void setDescription(String description) { | |
| this.description = description; | |
| } | |
| } | |
| private GenderStatus gender_status; | |
| public Employee() { | |
| } | |
| public Employee(GenderStatus gender_status) { | |
| super(); | |
| this.gender_status = gender_status; | |
| } | |
| @Enumerated(EnumType.STRING) | |
| @NotNull(message = "Please enter Gender Status") | |
| @Column(name = "gender_status") | |
| public GenderStatus getGender_status() { | |
| return gender_status; | |
| } | |
| public void setGender_status(GenderStatus gender_status) { | |
| this.gender_status = gender_status; | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * employee.jsp | |
| * | |
| */ | |
| <tr> | |
| <td>Gender Status</td> | |
| <td> | |
| <c:forEach var="gen_status" items="${genderStatusList }"> | |
| <form:radiobutton path="gender_status" | |
| value="${gen_status.code }" />${gen_status.description } | |
| </c:forEach> | |
| <form:errors path="gender_status" cssClass="error" /> | |
| </td> | |
| </tr> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * EmployeeController.java | |
| * | |
| */ | |
| modelMap.put("genderStatusList", Employee.GenderStatus.values()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment