-
Jun 3rd, 2012, 11:33 PM
#1
How to bind a set back to conreoller class in Spring MVC
hi friends,
I am really new to this forum and spring... I am trying to build a sample application with MVC. I have an issue.
I have 3 model classes. ModuleData for modules, PermissionsData for setting permissions for each module and RoleData for roles. While entering a new role, i had listed modules inside that JSP page and added 3 checkboxes.. I need to insert the role name and its details to the usr_role table and the permissions for each module for that role to usr_perm table.. How can i achieve that? My classes are like this....
public class ModuleData {
@Id
@GeneratedValue
@Column( name = "modId" )
private Integer modId;
@Column( name = "modName" )
private String modName;
@Column( name = "modDescription" )
private String modDescription;
@Column( name = "modIsDelete" )
private boolean modIsDelete;
//getters and Setters
}
public class PermissionsData {
@Id
@GeneratedValue
@Column ( name = "perId")
private Integer permissionID;
@Column ( name = "rlId")
private Integer roleID;
@Column ( name = "modId")
private Integer moduleID;
@Column ( name = "perIsreadOnly")
private boolean permissionIsReadOnly;
@Column ( name = "perIsModify")
private boolean permissionIsModify;
@Column ( name = "perIsFull")
private boolean permissionIsFull;
@Column ( name = "perIsDelete")
private boolean permissionIsDelete;
//getters and setters
}
public class RoleData {
@Id
@GeneratedValue
@Column( name = "rlId" )
@OneToMany(mappedBy = "role")
private Integer roleID;
@Column( name = "rlName" )
private String roleName;
@Column( name = "rlDescription" )
private String roleDescription;
@Column( name = "rlIsEnabled" )
private boolean roleIsEnabled;
@Column( name = "rlCreatedBy" )
private Integer roleCreatedBy;
@Column( name = "rlCreatedDate" )
private String roleCtreatedDate;
@Column( name = "rlIsDelete" )
private boolean roleIsDeleted;
@ManyToMany(fetch= FetchType.EAGER, cascade = CascadeType.PERSIST )
@JoinTable( name = "usr_permission",
joinColumns = { @JoinColumn(name = "roleID")},
inverseJoinColumns = { @JoinColumn(name = "modId")})
private Set<ModuleData> moduleList = new HashSet<ModuleData>();
//getters and setters
}
and in RoleController i have..
@RequestMapping(value = "/addRole")
public ModelAndView addNewRole()
{
ModelAndView mav = new ModelAndView("addNewRole");
RoleData role = new RoleData();
// for setting all modules to role
List<ModuleData> moduleList = moduleService.getAllModules();
Set<ModuleData> myModuleList = new HashSet<ModuleData>(moduleList);
role.setModuleList(myModuleList);
mav.getModelMap().put("roleDataObj", role);
return mav;
}
@RequestMapping(value = "/saveNewRole", method=RequestMethod.POST)
public String saveRole(@ModelAttribute("roleDataObj") RoleData role, BindingResult result, SessionStatus status)
{
// Here i need to get the help..
return "redirect:homePage.jav";
}
In that saveRole function in RoleController, i need to add the new role details to the database. and then the id of both role and module with permssion to the usr_perm table...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules