java - Spring 3.2.5 form tag radioButtons behavior -


can iterate collection of objects in form:radiobuttons in spring 3.2.5?

for instance in addemployee.jsp,

<td><form:radiobuttons path="empdepartmentname" items="${departments}"/></td> 

and method populate departments,

@requestmapping(value = "/", method = requestmethod.get)     public string homepage(modelmap map) {         map.addattribute("employee", new employee());         populatedepartments(map);         return "addemployee";     }      private void populatedepartments(modelmap map){         list<string> departments = new arraylist<string>();         departments.add("dept 1");         departments.add("dept 2");         map.addattribute("departments", departments);             } 

can departments list<department> , allow client select department name ui , map selected department directly in employee entity instead of going through transient variable empdepartmentname fetch department selected department name , assign department object employeee , persist employee. doing correct way?

@entity public class employee {      @id     @generatedvalue(strategy=generationtype.auto)     private integer id;     private string name;     private string address;      @transient     private string empdepartmentname;      @onetoone(fetch=fetchtype.lazy)     private department department; } 

to avoid doing transient class - take employee name, can use spring custom property editor convert string type.

custom property editors can used convert strings object type. so, on employee class can have department attribute , no need empdepname transient field.

here tutorial - https://www.credera.com/blog/technology-insights/java/spring-mvc-custom-property-editors/


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -