Displaying Correct information on my webpage. - java

My question is How can I use my getLabel, getX, getY from my NodeEntity class and display the results of my query on my web page instead of getting "org.neo4j.ogm.response.model". I do not know if these get methods should be used within the controller or repository class in order to display the node information on the web page table.
#NodeEntity
public class Room {
#Id #GeneratedValue
private Long id;
#Property(name = "label")
private String label;
#Property(name = "shape")
private String shape;
#Property(name = "colour")
private String colour;
#Property(name = "x")
private String x;
#Property(name = "y")
private String y;
#Relationship(type = "To")
private Collection<Room> roomTo = new ArrayList<>();
#Relationship(type = "Up")
private Collection<Room> roomUp = new ArrayList<>();
#Relationship(type = "Down")
private Collection<Room> roomDown = new ArrayList<>();
#JsonIgnoreProperties("room")
#Relationship(type = "To", direction = Relationship.INCOMING)
Collection<RelEnt> relEnts;
public Room(){
}
public String getLabel(){
return label;
}
public String getShape(){
return shape;
}
public String getColour(){
return colour;
}
public String getX() {
return x;
}
public String getY() {
return y;
}
}
Repository:
public interface NavigatorRepository extends Neo4jRepository<Room, String>{
#Query("match (r1: Room {label: {from}}), (r2: Room {label: {to}}), p = shortestPath((r1)-[*]-(r2)) unwind nodes(p) as room return room")
Iterable<Map<String, Object>> getShortestRoute(#Param("from") String from, #Param("to") String to);
}
Service:
#Service
public class NavigatorService {
#Autowired
NavigatorRepository navigatorRepository;
public Iterable<Map<String, Object>> shortestRoute(String from, String to){
return navigatorRepository.getShortestRoute(from, to);
}
}
Controller:
#Controller
public class AunController {
#RequestMapping(value = "/AUN") //this will allow you to access web page with just http://localhost:8081/
public String homePage(){
return "AUN-Web"; //uses the static html file created for the web page
}
#Autowired
NavigatorService navigatorService;
#GetMapping(value = "/navigate")
public String navigate(#RequestParam(name="from") String from, #RequestParam(name="to") String to, Model model) {
Iterable<Map<String, Object>> route = navigatorService.shortestRoute(from, to);
model.addAttribute("from", from)
.addAttribute("route", route)
.addAttribute("to", to);
return "AUN-Results";
}
#GetMapping(value = "/")
public String error(){
return "Error/404";
}
}
HTML:
<form action="/navigate" method="">
<strong><label for="ifrom">Current Location:</label></strong> <br>
<input id="ifrom" type="text" placeholder="MB" name="from"><br>
<strong><label for="ito">Destination:</label></strong> <br>
<input id="ito" type="text" placeholder="MB" name="to"><br>
<p style="line-height: 30px; width: 300px;"></p>
<button type="button" class="btn btn-success" onclick="result">Search</button>
<p style="line-height: 30px; width: 300px;"></p>
</form>
</div>
<div align="center" class="container-fluid">
<h5>Going from <span th:text="${from}">MB220</span> to <span th:text="${to}">MB265</span></h5>
<table class="table">
<tr>
<th>Label</th>
<th>X</th>
<th>Y</th>
</tr>
<tr th:each="route : ${route}">
<td th:text="${route}">Mb220</td>
</tr>
</table>
</div>

Try to change your foreach var name to something like "routpoint" so it differs to the complete route.

Related

Getting values from enum in thymeleaf

I'm using enum for select options in thymeleaf and I can't see them or insert them in the database. There is nothing in the dropdown list.
<div class="form-group">
<label for="roomType">Rooms</label>
<select class="form-select selectpicker show-tick" th:field="*{property.roomType}" id="rooms">
<option value="">Nothing selected</option>
<option th:each="property.roomType : ${T(com.realestate.petfriendly.entity.RoomType).values()}"
th:value="${property.roomType}"
th:text="${property.roomType}">
</option>
</select>
</div>
class
#Enumerated(EnumType.STRING)
#Column(name = "RoomType")
private RoomType roomType;
and enum
public enum RoomType {
GARSONJERA("garsonjera"), JEDNOIPOSOBAN("jednoiposoban"), DVOSOBAN("dvosoban"),
DVOIPOSOBAN("dvoiposoban"), TROSOBAN("trosoban"), TROIPOSOBAN("troiposoban"),
CERVOROSOBAN("cetvorosoban"), CETVOROIPOSOBAN("cetvoroiposoban"), VISESOBAN("visesoban");
private String roomType;
private RoomType(String roomType) {
this.roomType = roomType;
}
public String getRoomType() {
return this.roomType;
}
}
I'm not sure why it doesn't show me anything
that is available for me.
class
#Setter
#Getter
public class Demo {
private RoomType roomType;
}
enum
public enum RoomType {
GARSONJERA("garsonjera"), JEDNOIPOSOBAN("jednoiposoban"), DVOSOBAN("dvosoban"),
DVOIPOSOBAN("dvoiposoban"), TROSOBAN("trosoban"), TROIPOSOBAN("troiposoban"),
CERVOROSOBAN("cetvorosoban"), CETVOROIPOSOBAN("cetvoroiposoban"), VISESOBAN("visesoban");
private final String roomType;
private RoomType(String roomType) {
this.roomType = roomType;
}
public String getRoomType() {
return this.roomType;
}
}
controller:
#Controller
#RequestMapping( "test")
public class TestController {
#GetMapping("demo")
public String demo(Model model){
Demo demo = new Demo();
demo.setRoomType(RoomType.CERVOROSOBAN);
model.addAttribute(demo);
return "test/demo";
}
}
HTML:
<div class="form-group">
<label for="rooms">Rooms</label>
<select class="form-select selectpicker show-tick" th:field="*{demo.roomType}" id="rooms">
<option value="">Nothing selected</option>
<option th:each="value : ${T(com.bluray.boot.business.test.RoomType).values()}"
th:value="${value}"
th:text="${value}">
</option>
</select>
</div>
I use spring-boot 2.3.6.release

How to display records from a table with relationship mapping in Spring boot, CrudRepository and Thymeleaf

I am developing a simple CRUD project with Spring Boot. I have successfully accomplished connecting to the database and displaying records from ONE table. Now I want to show the "Phones" belonging to a "Client" but when I click on "VerDetalle" (http://localhost:8080/listar) it shows the table without any record (obviously the table has data)
I think the problem its with the method telefonosById(nro_cliente) of TelefonoService and verDetalle(#PathVariable Integer nro_cliente, Model model) of Controller.
"E01_cliente" and "E01_telefono" they are entities.
#Entity
public class E01_telefono {
private Integer codigo_area;
#Id
private Integer nro_telefono;
private char tipo;
private Integer nro_cliente;
#ManyToOne
private E01_cliente cliente;
//**Constructor and Getters and Setters**//
Entity E01_cliente:
#Entity
public class E01_cliente {
#Id
private Integer nro_cliente;
private String nombre;
private String apellido;
private String direccion;
private boolean activo;
#OneToMany(mappedBy = "cliente")
private Set<E01_telefono> telefonos;
}
Service Telefono:
#Service
public class TelefonoService implements IServiceTelefono {
#Autowired
private ITelefono telData;
#Override
public List<E01_telefono> AllPhones() {
return (List<E01_telefono>) telData.findAll();
}
#Override
public Optional<E01_telefono> telefonosById(Integer nro_cliente) {
return telData.findById(nro_cliente);
}
Controller:
#Controller
public class Controlador {
#Autowired
private IServiceCliente serviceCliente;
#Autowired
private IServiceTelefono serviceTelefono;
#GetMapping("/listar")
public String listarClientes(Model model){
List<E01_cliente> clientes = serviceCliente.listarClientes();
model.addAttribute("clientes", clientes);
return "index";
}
#GetMapping("/agregarCliente")
public String agregarCliente(Model model){
model.addAttribute("cliente", new E01_cliente());
//Cuando el usuario presione se mostrara el formulario correspondiente al Cliente
return "formulario";
}
#PostMapping("/guardarCliente")
public String guardarCliente(Model model, #Valid E01_cliente cliente){
serviceCliente.guardarCliente(cliente);
return "redirect:/listar";
}
#GetMapping("/editarCliente/{nro_cliente}")
public String editarCliente(#PathVariable Integer nro_cliente, Model model ){
Optional<E01_cliente> clientEdit = serviceCliente.listarId(nro_cliente);
model.addAttribute("cliente", clientEdit);
return "formulario";
}
#GetMapping("/eliminarCliente/{nro_cliente}")
public String borrarCliente(Model model, #PathVariable Integer nro_cliente){
serviceCliente.eliminarCliente(nro_cliente);
return "redirect:/listar";
}
#GetMapping("/verDetalle/{nro_cliente}")
public String verDetalle(#PathVariable Integer nro_cliente, Model model){
Optional<E01_telefono> telefonosCliente = serviceTelefono.telefonosById(nro_cliente);
if(telefonosCliente.isPresent()) {
model.addAttribute("telefonos", telefonosCliente);
}
return "detalleCliente";
}
}
HTML Thymeleaf "detalleCliente.html":
<body>
<div class="container mt-4">
<table class="table">
<thead>
<tr>
<th>Código Área</th>
<th>Teléfono</th>
<th>Tipo</th>
<th>Número Cliente</th>
</tr>
</thead>
<tbody>
<tr th:each="telefono:${telefonos}">
<td th:text="${telefono.codigo_area}"></td>
<td th:text="${telefono.nro_telefono}"></td>
<td th:text="${telefono.tipo}"></td>
<td th:text="${telefono.nro_cliente}"></td>
</tr>
</tbody>
</table>
</div>
</body>
If you want to put E01_cliente cliente from telefonosCliente to ${telefonos} try change
model.addAttribute("telefonos", telefonosCliente);
To
model.addAttribute("telefonos", telefonosCliente.get().getClientes());

Why these lists don't work? (spring - mvc)

i've been asked to learn java and spring mvc for work but seems i'm not really good at it :(
Anyway i'm trying to create two lists dynamically the first one works, the second doesn't (i didn't really understand the get and post methods i fear) can you tell me why?
#Controller
#RequestMapping(value = "/")
public class ConfigController {
#RequestMapping(value = "home", method = RequestMethod.GET)
public String saveNum(Model model) {
model.addAttribute("configuration", new Config());
return "home";
}
#RequestMapping(value = "home", method = RequestMethod.POST)
public String saveNumPost(#ModelAttribute(value = "configuration") Config config, Model model) {
List<Driver> drivers = new ArrayList<Driver>();
for (int i = 0; i < config.getDriversNum(); i++) {
drivers.add(new Driver());
}
Championship championship = new Championship();
championship.setDrivers(drivers);
model.addAttribute("championship", championship);
return "configDrivers";
}
#RequestMapping(value = "configDrivers", method = RequestMethod.GET)
public String saveDriverList() {
return "configDrivers";
}
#RequestMapping(value = "configDrivers", method = RequestMethod.POST)
public String createCars(#ModelAttribute Championship championship, Config config, Model model) {
List<Car> cars = new ArrayList<Car>();
for (int i = 0; i < championship.getDrivers().size(); i++) {
cars.add(new Car());
}
championship.setCars(cars);
model.addAttribute("championship", championship);
return "configCars";
}
#RequestMapping(value = "configCars", method = RequestMethod.GET)
public String saveTrackNum(#ModelAttribute Config config, Model model) {
model.addAttribute("configuration", config);
return "trackNum";
}
#RequestMapping(value = "trackNum", method = RequestMethod.POST)
public String saveTracks(#ModelAttribute(value = "configuration") Config config, Championship championship,
Model model) {
List<Track> tracks = new ArrayList<Track>();
for (int i = 0; i < config.getTracksNum(); i++) {
tracks.add(new Track());
}
championship.setTracks(tracks);
model.addAttribute("championship", championship);
return "configTracks";
}
}
home view
<c:url var="url" value="/home"/>
<form:form action="${url}" method="POST" modelAttribute="configuration">
<label>Insert number of drivers:</label> <br>
<form:input path="driversNum" placeholder="Type drivers number"/>
<br>
<input type="submit" />
<!--number races-->
</form:form>
configDrivers view
<c:url var="url" value="/configDrivers"/>
<form:form action="${url}" method="POST" modelAttribute="championship">
<label>Insert drivers:</label>
<c:forEach items="${championship.drivers}" var="driver" varStatus="i">
<h3>Insert driver's name and surname of driver ${i.index} </h3>
<form:input path="drivers[${i.index}].name" value="${driver.name}" placeholder="Type name here" />
<br>
<form:input path="drivers[${i.index}].surname" value="${driver.surname}" placeholder="Type surname here" />
<br>
</c:forEach>
<input type="submit" />
<!--number races-->
</form:form>
configCars view
<c:url var="url" value="/configCars"/>
<form:form action="${url}" method="POST" modelAttribute="championship">
<label>Insert cars:</label>
<c:forEach items="${championship.cars}" var="car" varStatus="i">
<h3>Insert driver's team ${i.index} </h3>
<form:input path="cars[${i.index}].team" value="${car.team}" placeholder="Type team here" />
<br>
</c:forEach>
<input type="submit" />
<!--number races-->
</form:form>
<select>
<c:forEach items="${championship.drivers}" var="car" varStatus="i">
<option value="${i.index}">${driver.name}</option>
</c:forEach>
</select>
the Car class
public class Car {
private String team;
private Driver driver;
public String getTeam() {
return team;
}
public void setTeam(String team) {
this.team = team;
}
public Driver getDriver() {
return driver;
}
public void setDriver(Driver driver) {
this.driver = driver;
}
}
an the championship class (the one with the lists)
public class Championship {
private List<Driver> drivers;
private List<Car> cars;
private List<Track> tracks;
public List<Driver> getDrivers() {
return drivers;
}
public void setDrivers(List<Driver> drivers) {
this.drivers = drivers;
}
public List<Car> getCars() {
return cars;
}
public void setCars(List<Car> cars) {
this.cars = cars;
}
public List<Track> getTracks() {
return tracks;
}
public void setTracks(List<Track> tracks) {
this.tracks = tracks;
}
}
Can you paste this code :
List<Car> cars = new ArrayList<Car>();
for (int i= 0; i < config.getDriversNum(); i++) {
cars.add(new Car());
}
Championship championship = new Championship();
championship.setCars(cars);
model.addAttribute("championship",championship);
inside the printDrivers() method and check.
I think that should do the trick.

JSP Method not found: class java.lang.String

I have this exception andd i can't find a solution
COntroller :
#RequestMapping(value="/sujet")
public String detail(Model model, HttpServletRequest request, Long idSujet) {
Utilisateur user = (Utilisateur) request.getSession().getAttribute("user");
model.addAttribute("nbrMails", metierUtilisateur.listDesEmailsRecuNonLu(user.getIdUtilisateur()).size());
SujetForum sujet = metierSujetForum.findById(idSujet);
sujet.setMessagesForums(metierSujetForum.getListMessageForum(idSujet));
model.addAttribute("sujet", sujet);
model.addAttribute("messages", metierSujetForum.getListMessageForum(idSujet));
return "/coordinateur/detailSujetForum";
}
this is my Bean definition :
i defined all the getters and setters for all attributes but is till get the same exception
#Entity
public class MessagesForum implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idMessage;
private String message;
private Date dateDepotMessage;
private boolean messageCorrecte;
#ManyToOne
#JoinColumn(name = "idSujet")
private SujetForum sujetForum;
#ManyToOne
#JoinColumn(name = "idUtilisateur")
private Utilisateur utilisateur;
#OneToMany(mappedBy = "messageForum")
private Collection<PieceJointeForum> pieceJointeForums;
public MessagesForum(String message, Date dateDepotMessage, boolean messageCorrecte) {
super();
this.message = message;
this.dateDepotMessage = dateDepotMessage;
this.messageCorrecte = messageCorrecte;
}
public MessagesForum() {
super();
}
public Long getIdMessage() {
return idMessage;
}
public void setIdMessage(Long idMessage) {
this.idMessage = idMessage;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Date getDateDepotMessage() {
return dateDepotMessage;
}
public void setDateDepotMessage(Date dateDepotMessage) {
this.dateDepotMessage = dateDepotMessage;
}
public boolean isMessageCorrecte() {
return messageCorrecte;
}
public void setMessageCorrecte(boolean messageCorrecte) {
this.messageCorrecte = messageCorrecte;
}
public SujetForum getSujetForum() {
return sujetForum;
}
public void setSujetForum(SujetForum sujetForum) {
this.sujetForum = sujetForum;
}
public Utilisateur getUtilisateur() {
return utilisateur;
}
public void setUtilisateur(Utilisateur utilisateur) {
this.utilisateur = utilisateur;
}
public Collection<PieceJointeForum> getPieceJointeForums() {
return pieceJointeForums;
}
public void setPieceJointeForums(Collection<PieceJointeForum> pieceJointeForums) {
this.pieceJointeForums = pieceJointeForums;
}
}
this is the output of the exception
615: <div class="media-body">
616: <div class="media-text">
617: <h5 class="semibold mt0 mb5 text-accent"></h5>
618: <p class="mb5">${msg.getIdMessage() }.</p>
619: <!-- meta icon -->
620: <p class="mb0">
621: <span class="media-meta"></span> <span class="mr5 ml5 text-muted">*</span> <a href="javascript:void(0);" class="media-meta text-default" data-t
oggle="tooltip" title="" data-original-title="Reply"><i class="ico-reply"></i></a>
Stacktrace:] with root cause
javax.el.MethodNotFoundException: Method not found: class java.lang.String.getIdMessage()
at javax.el.Util.findWrapper(Util.java:352)
at javax.el.Util.findMethod(Util.java:214)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:174)
at org.apache.jasper.el.JasperELResolver.invoke(JasperELResolver.java:139)
at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:967)
at org.apache.jsp.WEB_002dINF.views.coordinateur.detailSujetForum_jsp._jspx_meth_c_005fforEach_005f0(detailSujetForum_jsp.java:1242)
at org.apache.jsp.WEB_002dINF.views.coordinateur.detailSujetForum_jsp._jspService(detailSujetForum_jsp.java:832)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
<c:forEach items="=${messages }" var="msg">
<div class="media-list media-list-bubble">
<div class="media">
<a href="javascript:void(0);" class="media-object pull-left"> <img src="" class="img-circle" alt="">
</a>
<div class="media-body">
<div class="media-text">
<h5 class="semibold mt0 mb5 text-accent"></h5>
<p class="mb5">${msg.idMessage }.</p>
<!-- meta icon -->
<p class="mb0">
<span class="media-meta"></span> <span class="mr5 ml5 text-muted">*</span> <i class="ico-reply"></i>
</p>
<!--/ meta icon -->
</div>
</div>
</div>
</div>
</c:forEach>
msg in JSP here seems to be coming as String and You are expecting your bean Class type .
After you get the bean also
${msg.getIdMessage() }.
This seems to be issue in your JSP. just try with
${msg.idMessage() }.
send me your jsp and don't call with get method u should call directly with property values. like amit.rk3 said. and where you are using this msg in your jsp
use like this
<c:forEach var="msg" items="${messages}">

how to databind list selected checkbox in spring mvc

Hi I am new to Spring Mvc i have 3 tables first is role,resources,roleresource tables respectively. I have a created a jsp in which a list of resources are shown along with check boxes and also rolename where user enters,my prob is i need to insert rolename to role table and generated roleid to roleresource table with selected resources ids. problem here is i am not able to bind selected checkbox values here is my controller
package com.steadyground.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.steadyground.constants.URLConstants;
import com.steadyground.entity.Organization;
import com.steadyground.entity.Resources;
import com.steadyground.form.RoleResourceForm;
import com.steadyground.service.ResourcesService;
#Controller
public class RoleResoucesMappingController {
#Autowired
private ResourcesService resourcesService;
#RequestMapping(value = URLConstants.ROLERESOURCEMAPPING_PAGE, method = RequestMethod.GET)
public String landRoleResourceMapping(ModelMap map)
{
map.addAttribute("roleResourceForm",new RoleResourceForm());
return "roleResourcesMapping";
}
#RequestMapping(value = URLConstants.ROLERESOURCEMAPPING_ADD, method = RequestMethod.POST)
public String createRoleResourceMapping(#ModelAttribute(value="roleResourceForm") RoleResourceForm roleResourceForm, BindingResult result, ModelMap map)
{
System.out.println(roleResourceForm.getResources());
System.out.println(roleResourceForm.getResources().size());
//System.out.println(roleResourceForm.getRole().getRoleResources());
return "roleResourcesMapping";
}
#ModelAttribute("resources")
public List<Resources> getAllResources() {
List<Resources> listResources = new ArrayList<Resources>();
listResources = resourcesService.getAllResources();
return listResources;
}
}
here is my role.java file
#Entity
#Table(name = "role", catalog = "steadyground")
public class Role implements java.io.Serializable {
private Integer roleId;
private String roleName;
private Set<RoleResource> roleResources = new HashSet<RoleResource>(0);
public Role() {
}
public Role(String roleName) {
this.roleName = roleName;
}
public Role(String roleName, String applicationName,
Set<RoleResource> roleResources) {
this.roleName = roleName;
this.roleResources = roleResources;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "role_id", unique = true, nullable = false)
public Integer getRoleId() {
return this.roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
#Column(name = "role_name", nullable = false, length = 100)
public String getRoleName() {
return this.roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
#OneToMany(fetch = FetchType.LAZY, mappedBy = "role")
public Set<RoleResource> getRoleResources() {
return this.roleResources;
}
public void setRoleResources(Set<RoleResource> roleResources) {
this.roleResources = roleResources;
}
}
here is my resources.java
#Entity
#Table(name = "resources", catalog = "steadyground")
public class Resources implements java.io.Serializable {
private Integer resourceId;
private String url;
private String urlName;
public Resources() {
}
public Resources(String url, String urlName) {
this.url = url;
this.urlName = urlName;
}
#Id
#GeneratedValue(strategy = IDENTITY)
#Column(name = "resource_id", unique = true, nullable = false)
public Integer getResourceId() {
return this.resourceId;
}
public void setResourceId(Integer resourceId) {
this.resourceId = resourceId;
}
#Column(name = "url", length = 100)
public String getUrl() {
return this.url;
}
public void setUrl(String url) {
this.url = url;
}
#Column(name = "url_name", length = 200)
public String getUrlName() {
return this.urlName;
}
public void setUrlName(String urlName) {
this.urlName = urlName;
}
}
here is my roleresource.java
#Entity
#Table(name="role_resource"
,catalog="steadyground"
)
public class RoleResource implements java.io.Serializable {
private Integer roleResourceId;
private Role role;
private Integer resourceId;
public RoleResource() {
}
public RoleResource(Role role, Integer resourceId) {
this.role = role;
this.resourceId = resourceId;
}
#Id #GeneratedValue(strategy=IDENTITY)
#Column(name="role_resource_id", unique=true, nullable=false)
public Integer getRoleResourceId() {
return this.roleResourceId;
}
public void setRoleResourceId(Integer roleResourceId) {
this.roleResourceId = roleResourceId;
}
#ManyToOne(fetch=FetchType.LAZY)
#JoinColumn(name="role_id")
public Role getRole() {
return this.role;
}
public void setRole(Role role) {
this.role = role;
}
#Column(name="resource_id")
public Integer getResourceId() {
return this.resourceId;
}
public void setResourceId(Integer resourceId) {
this.resourceId = resourceId;
}
}
and my jsp page
<springform:form method="post" action="createRoleResourcesMapping" class="form-horizontal" commandName="roleResourceForm" >
<div class="span12">
<div class="center">
<div class="control-group span6">
<label class="control-label" for="Role_Id">Role Id</label>
<div class="control-group span6">
<label class="control-label" for="url_Name">Role Name</label>
<div class="controls">
<div class="span12">
<springform:input path="role.roleName"/>
</div>
</div>
</div>
<div class="page-header position-relative"></div>
<table id="sample-table-2" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Resources</th>
</tr>
</thead>
<tbody>
<tr>
<td><springform:checkboxes path="resources" items="${resources}" itemLabel="urlName" itemValue="resourceId"/>
</td></tr></tbody>
</table>
<div class="controls">
<div class="span12">
<input type="submit" class="btn btn-primary" value="Submit">
<input type="button" class="btn " value="Cancel">
</div>
</div>
</div>
</div>
</springform:form>
could someone help me in how to receive the data and save it in two tables
<springform:checkboxes path="resources" items="${resources}" itemLabel="urlName" itemValue="resourceId"/>
From your code, what I've understood, the RoleResourcesForm is more like a wrapper of the 2 entities Resource & Role with another object resources.
I think, to use form:checkboxes you better give it an object List in the path.
And what's this variable resources?
If it's really an List object in the RoleResourcesForm wrapper, in the items, you should use
items="${roleResourceForm.resources}"
When you commit it, it will send the form model attribute with only checked checkbox values.

Categories

Resources