Skip to content

Instantly share code, notes, and snippets.

@jpukg
Created October 10, 2016 18:40
Show Gist options
  • Select an option

  • Save jpukg/eb7278d74088db67a41bba6a5f31b4ad to your computer and use it in GitHub Desktop.

Select an option

Save jpukg/eb7278d74088db67a41bba6a5f31b4ad to your computer and use it in GitHub Desktop.
Spring MVC radiobutton example
/*
* 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;
}
}
/*
* 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>
/*
* 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