Thymeleaf nested Set<Object> - html

I'm having a problem accessing a nested Set of objects.
I have defined the below objects :
#Getter
#Setter
#AllArgsConstructor
#NoArgsConstructor
#Entity
#Table(name = "site")
public class Site {
#Id
#GeneratedValue(strategy = GerationType.IDENTITY)
#Column(name="id", updatable=false,nullable=false)
private Long id;
private String siteName;
private String siteLocation;
#OneToMany(cascade=CascadeType.ALL, mappedBy = "site")
private Set<Rack> rack = new HashSet<>();
}
#Getter
#Setter
#AllArgsConstructor
#NoArgsConstructor
#Entity
#Table(name = "rack")
public class Rack {
#Id
#GeneratedValue(strategy = GerationType.IDENTITY)
#Column(name="id", updatable=false,nullable=false)
private Long id;
private String rackName;
private String rackAssetTag;
private String rackCMDBCode;
#ManyToOne
#JoinColumn(name = "site_id")
private Site site;
#OneToMany(cascade=CascadeType.ALL, mappedBy = "box")
private Set<Box> box = new HashSet<>();
}
#Getter
#Setter
#AllArgsConstructor
#NoArgsConstructor
#Entity
#Table(name = "box")
public class Box {
#Id
#GeneratedValue(strategy = GerationType.IDENTITY)
#Column(name="id", updatable=false,nullable=false)
private Long id;
private boxAssetTag;
private boxCMDBCode;
ManyToOne
#JoinColumn(name = "rack_id")
private Rack rack;
}
All relation mapping work tiptop.
The problem is when I want to create a nice nested table for this(css formating and conditional thymeleaf validation removed since it's irrelevant) :
<div>
<table>
<thead>
<tr>
<th>Rack name</th>
<th>Rack asset tag</th>
<th>Rack CMDB code</th>
</tr>
</thead>
<tbody>
<tr th:each="rack:${site.rack}">
<td th:text="${rack.rackName}"></td>
<td th:text="${rack.rackAssetTag}"></td>
<td th:text="${rack.rackCMDBCode}"></td>
</tr>
<tr>
<td>
<table>
<thead>
<tr>
<th>Box asset tag</th>
<th>Box CMDB code</th>
</tr>
</thead>
<tbody>
<tr th:each="box:${rack.box}">
<td th:text="${box.boxAssetTag}">
<td th:text="${box.boxCMDBCode}">
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
Controller adds one object 'site' to the model that holds all relation.
When accessing the page I receive and error:
Property or field 'box' cannot be found on null
I think that when I move to the second table thymeleaf looses the context of the object rack created in the outer table. Therefore when I try to invoke the th:each in the inner table the there is no rack object to perform ${rack.box}.
The question is how to be able to access the 'deeper' object in thymeleaf without loosing the context of the object above?
Regards,
Jarek.

Ok so I've managed to work out a solution.
I'll write it up. Maybe someone some day will need it.
So the idea is to cycle through each object but on the body element not on the row. This lets You have the context of the object much wider
<div>
<table>
<thead>
<th>Rack name</th>
<th>Rack asset tag</th>
<th>Rack CMDB code</th>
</thead>
<tbody th:each="rack:${site.rack}">
<tr>
<td th:text="${rack.rackName}"></td>
<td th:text="${rack.rackAssetTag}"></td>
<td th:text="${rack.rackCMDBCode}"></td>
</tr>
<tr>
<td>
<table>
<thead>
<tr>
<th>Box asset tag</th>
<th>Box CMDB code</th>
</tr>
</thead>
<tbody>
<tr th:each="box:${rack.box}">
<td th:text="${box.boxAssetTag}">
<td th:text="${box.boxCMDBCode}">
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

Related

Thymeleaf looping over list of objects with list of objects attribute problem

I'm working in Spring Boot and I have a problem rendering with Thymeleaf a table with different lines. First must be a String, and the subsequent lines must be the data saved in a list of objects.
situation of the problem:
I have a list of objects, this object has two attributes, one is a list of Strings, and the other one is a list of different objects. I don't know how to render in Thymeleaf in a table the first attribute of a string list in a line, and on the next lines of the table render the second list of attribute object.
details of the object:
public class objetosDeServiciosAD {
private String Servicio;
private LinkedList<usuarioAD> listaUsuariosAD;
public String getServicio() {
return Servicio;
}
public void setServicio(String servicio) {
Servicio = servicio;
}
public LinkedList<usuarioAD> getListaUsuariosAD() {
return listaUsuariosAD;
}
public void setListaUsuariosAD(LinkedList<usuarioAD> listaUsuariosAD) {
this.listaUsuariosAD = listaUsuariosAD;
}
#Override
public String toString() {
return "objetosDeServiciosAD [Servicio=" + Servicio + ", listaUsuariosAD=" + listaUsuariosAD + "]";
}
}
objetos_Servicios is a list of objects with two atributes, one is servicio
this object has a second attibute which is a list of objects, this is listaUsuariosAD.
This is my code in Thymeleaf:
<table class="table table-hover">
<thead class="thead-light">
<tr>
<th scope="col">Usuario</th>
<th scope="col">Teléfono</th>
<th scope="col">mail</th>
<th scope="col">Descripción</th>
</tr>
</thead>
<tbody>
<tr th:each="servicio : ${objetos_Servicios}">
<td th:text="${servicio.servicio}"></td>
<tr th:each=" listaeusuario : ${servicio.listaUsuariosAD}">
<tr th:each ="usuarios : ${listaeusuario}">
<td th:text = "${usuarios.usuario}"></td>
<td th:text = "${usuarios.telefono}"></td>
<td th:text = "${usuarios.mail}"></td>
<td th:text = "${usuarios.descripion}"></td>
</tr>
</tr>
</tbody>
</table>
The code will look something like this:
<table class="table table-hover">
<thead class="thead-light">
<tr>
<th scope="col">Usuario</th>
<th scope="col">Teléfono</th>
<th scope="col">mail</th>
<th scope="col">Descripción</th>
</tr>
</thead>
<tbody>
<th:block th:each="servicio : ${objetos_Servicios}">
<tr>
<td th:text="${servicio.servicio}" />
</tr>
<tr th:each = "lista : ${servicio.getListaUsuariosAD()}">
<td th:text="${lista.usuario}"></td>
<td th:text="${lista.telefono}"></td>
<td th:text="${lista.mail}"></td>
<td th:text="${lista.Descripcion}"></td>
</tr>
</th:block>
</tbody>
</table>
You can use a th:block tag to loop over a larger block of code (that contains the header <tr /> and the rows <tr />).
I recommend changing the naming standards you are using, so that all your class names begin with an upper-case letter - for example: ObjetosDeServiciosAD instead of objetosDeServiciosAD. This is standard in Java - and not doing this can be confusing for other people who read your code.
So, your class becomes:
import java.util.List;
public class ObjetosDeServiciosAD {
private String servicio;
private List<UsuarioAD> listaUsuariosAD;
public String getServicio() {
return servicio;
}
public void setServicio(String servicio) {
this.servicio = servicio;
}
public List<UsuarioAD> getListaUsuariosAD() {
return listaUsuariosAD;
}
public void setListaUsuariosAD(List<UsuarioAD> listaUsuariosAD) {
this.listaUsuariosAD = listaUsuariosAD;
}
}
I also replaced LinkedList with List, since you do not appear to need a linked list here (if you actually do, you can revert that change).
Then, for your Thymeleaf template, you can use Thymeleaf's <th:block> tag to structure your iteration loops:
<table class="table table-hover">
<thead class="thead-light">
<tr>
<th scope="col">Usuario</th>
<th scope="col">Teléfono</th>
<th scope="col">mail</th>
<th scope="col">Descripción</th>
</tr>
</thead>
<tbody>
<th:block th:each="servicio : ${objetos_Servicios}">
<tr>
<td th:text="${servicio.servicio}" />
<td></td>
<td></td>
<td></td>
</tr>
<tr th:each = "lista : ${servicio.listaUsuariosAD}">
<td th:text="${lista.usuario}"></td>
<td th:text="${lista.telefono}"></td>
<td th:text="${lista.mail}"></td>
<td th:text="${lista.descripcion}"></td>
</tr>
</th:block>
</tbody>
</table>
In the above code, I also replaced ${servicio.getListaUsuariosAD()} with the simpler ${servicio.listaUsuariosAD}, since you do not need to explicitly call the method, here.
I also added three empty <td></td> cells to ensure each row is complete, for the row displaying the servicio text.

Thymeleaf Table Rows Divide in separate Pages

I have table with 212 rows and I would like to split them between pages so that all pages have 25 rows and last page 12 rows.
I would like to know if this is possible at all with Thymeleaf or should I use something else for that.
And is it possible to calculate total values per page also?
Here is the pdf file: https://www.docdroid.net/TSLdFA1/report1.pdf
the is sample code for the controller
#Controller
public class BookController {
#Autowired
private BookService bookService;
#RequestMapping(value = "/listBooks", method = RequestMethod.GET)
public String listBooks(
Model model,
#RequestParam("page") Optional<Integer> page,
#RequestParam("size") Optional<Integer> size) {
int currentPage = page.orElse(1);
int pageSize = size.orElse(5);
Page<Book> bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize));
model.addAttribute("bookPage", bookPage);
int totalPages = bookPage.getTotalPages();
if (totalPages > 0) {
List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
.boxed()
.collect(Collectors.toList());
model.addAttribute("pageNumbers", pageNumbers);
}
return "listBooks.html";
}
}
and here is Thymeleaf Template
<table border="1">
<thead>
<tr>
<th th:text="#{msg.id}" />
<th th:text="#{msg.name}" />
</tr>
</thead>
<tbody>
<tr th:each="book, iStat : ${bookPage.content}"
th:style="${iStat.odd}? 'font-weight: bold;'"
th:alt-title="${iStat.even}? 'even' : 'odd'">
<td th:text="${book.id}" />
<td th:text="${book.name}" />
</tr>
</tbody>
</table>
<div th:if="${bookPage.totalPages > 0}" class="pagination"
th:each="pageNumber : ${pageNumbers}">
<a th:href="#{/listBooks(size=${bookPage.size}, page=${pageNumber})}"
th:text=${pageNumber}
th:class="${pageNumber==bookPage.number + 1} ? active"></a>
</div>

How to declare pagination pagesize in web.config or to my view

I have implemented paging using PageList.MVC. Now I need to that i can change the pagesize from my web.config. Any idea ....
Here is my controller:
public ActionResult UsersWhoHaveConsumedFreeCredit(int Id = 1)
{
var result = Manager.GetUsersWhoHaveConsumedFreeCredit();
JavaScriptSerializer serializer = new JavaScriptSerializer();
var model = serializer.Deserialize<List<CallHistory>>(result);
int pageSize = 100;
//int pageNumber = (page ?? 1);
return View(model.ToPagedList(Id, pageSize));
}
And this is my view
#model PagedList.IPagedList<MyYello.Admin.Models.CallHistory>
#{
ViewBag.Title = "UsersWhoHaveConsumedFreeCredit";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Users Who Have Consumed Free Credit</h2>
#*<table class="table table-striped table-bordered tablesorter" style="display: block">
<thead>
<tr>
<th>Login</th>
<th>FirstName</th>
<th>LastName</th>
<th>Email</th>
<th>Country</th>
<th>TarrifDesc</th>
<th>CalledNum</th>
<th>CallStart</th>
<th>CallEnd</th>
</tr>
</thead>*#
#foreach (var group in Model.GroupBy(dialed => dialed.Login))
{
var item = group.First();
{
<table>
<tbody>
<th class="custom-padding">Login Id</th>
<th class="custom-padding">Phone</th>
<th class="custom-padding">First Name</th>
<th class="custom-padding">Last Name</th>
<th class="custom-padding">Email</th>
<th class="custom-padding">Country</th>
<tr>
<td class="custom-padding">#item.Login </td>
<td class="custom-padding">#item.Phone</td>
<td class="custom-padding">#item.FirstName</td>
<td class="custom-padding">#item.LastName</td>
<td class="custom-padding">#item.Email</td>
<td class="custom-padding">#item.Country</td>
<th class="custom-padding">Dialed Calls:-</th>
<td class="custom-padding">#string.Join(" - ", group.Select(dialed => dialed.DialedNumber))</td> </tr>
#*<td>#item.FirstName</td>
<td>#item.LastName</td>
<td>#item.Email</td>
<td>#item.Country</td>*#
#*<td>#string.Join(" - ", group.Select(history => history.Phone))</td>*#
<tr> #*<td>#item.TariffDescription</td>*#
</tr>
</tbody>
</table>
<hr />
}
}
#* #Html.PagedListPager( (IPagedList)ViewBag.pageNumber, page => Url.Action ("UsersWhoHaveConsumedFreeCredit", new {page}));*#
<div class="paged-list">
#Html.PagedListPager(Model, Id => Url.Action("UsersWhoHaveConsumedFreeCredit", new { Id }), PagedListRenderOptions.Classic)
</div>
#if (!Model.Any())
{
<h2>No Record Found</h2>
}
I don't think you want this to be controlled from web.config however, you can do this by having a key inside appsettings section in web.config file.
<appSettings>
<key name="pageSize" value="10"/>
</appSettings>
And then you can access inside your code as
int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["pageSize"])
Typically you would want users to control pageSize from the view.

Foreign key reference in spring mysql hibernate

Hi i am writing a spring mvc hibernate annotation application there i have 2 tables "team" and another table "players".Here i am using one-to-one mapping and mysql database.In players table i am keeping player records like name,years active etc.The "team" table contains two entries teamid(primary key)and teamname.
The "players" table contains the foreign key teamid.Here when i try to delete a teamname without deleting all its references in players table i am getting error message
HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query
so when i delete all the references ,then there is no error.So how can i find all the refrences before deleting.I am interested in showing an alert message using javascript which warns to delete all references.I know how to create simple alert message in javascript,but here i have to show the alert only if there is a reference to foreign key.And i want to know is there any alternate way to delete the foriegn key reference without affecting the "players" table.
AddTeam.java
#Entity
#Table(name="Team")
public class AddTeam {
#Id
#Column(name="teamId")
private Integer teamId;
#Column(name="teamName")
private String teamName;
public Integer getTeamId() {
return teamId;
}
public void setTeamId(Integer teamId) {
this.teamId = teamId;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
}
Player.java
#Entity
#Table(name="playerdata")
public class Player implements Serializable {
private static final long serialVersionUID = -723583058586873479L;
/**
*
*/
#Id
#Column(name="playerid")
private Integer playerId;
#Column(name="playername")
private String playerName;
#Column(name="yearsactive")
private Integer yearsActive;
#Column(name="country")
private Integer Country;
#OneToOne
#JoinColumn(name="teamId")
private AddTeam teams;
public Integer getPlayerId(){
return playerId;
}
public void setPlayerId(Integer playerId){
this.playerId=playerId;
}
public String getPlayerName(){
return playerName;
}
public void setPlayerName(String playerName){
this.playerName=playerName;
}
public String getCountry(){
return Country;
}
public void setCountry(String Country){
this.Country=Country;
}
public Integer getyearsActive(){
return yearsActive;
}
public void setyearsActive(Integer yearsActive){
this.yearsActive=yearsActive;
}
public AddTeam getTeams() {
return teams;
}
public void setTeams(AddTeam teams) {
this.teams = teams;
}
}
and this is the query used in playerDaoImplementation.java class
#Override
public void deleteResource(int playerid) {
// TODO Auto-generated method stub
sessionfactory.getCurrentSession().createQuery("DELETE FROM Resource WHERE playerid=" +playerid).executeUpdate();
}
Query used to delete in AddteamDaoImplementation.java
#Override
public void deleteTeams(int teamid) {
// TODO Auto-generated method stub
sessiofactory.getCurrentSession().createQuery("DELETE FROM AddTeam WHERE teamid="+teamid).executeUpdate();
}
deletefunction in PlayerController.java
#RequestMapping(value="/deletePlayer",method=RequestMethod.GET)
public ModelAndView deletePlayerDetails(#ModelAttribute("command") Player player,
BindingResult result){
playerService.deletePlayer(player.getPlayerId());
Map<String, Object> model = new HashMap<String, Object>();
model.put("playerkey", playerService.listPlayer());
model.put("teamKey", addteamService.listTeams());
return new ModelAndView("EditPlayer",model);
}
Team.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Players Manager</title>
<center>
<h2>Add Team Details</h2>
<form:form method="POST" action="Team.html">
<table>
<tr>
<td><form:label path="teamId">Team ID:</form:label></td>
<td><form:input path="teamId" id="demo" value="${team.teamId}"/></td>
</tr>
<tr>
<td><form:label path="teamName">Team Name:</form:label></td>
<td><form:input path="teamName" value="${team.teamName}"/></td>
</tr>
<tr>
<tr>
<td> </td>
<td><input type="submit" value="SAVE"/></td>
</tr>
</table>
</form:form>
<br/>
<c:if test="${!empty teamKey}">
<table align="center" border="1">
<tr>
<th>Category ID</th>
<th>Category Name</th>
<th>Options</th>
</tr>
<c:forEach items="${teamKey}" var="team">
<tr>
<td><c:out value="${team.teamId}"/></td>
<td><c:out value="${team.teamName}"/></td>
<td align="center">Edit |
Delete</td>
</tr>
</c:forEach>
</table>
</c:if>
<h2>Adding Publication</h2>
</center>
</body>
</html>
EditPlayer.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Resource Manager</title>
</head>
<body>
<center>
<h2>Add Players</h2>
<form:form method="POST" action="save.html">
<table>
<tr>
<td><form:label path="playerId">Player Id</form:label></td>
<td><form:input path="playerId" value= "${player.playerId }"/></td>
</tr>
<tr>
<td><form:label path="playerName">Name</form:label></td>
<td><form:input path="playerName" value="${player.playerName }"/></td>
</tr>
<tr>
<td><form:label path="YearsActive">Experience</form:label></td>
<td><form:input path="YearsActive" value="${player.YearsActive }"/></td>
</tr>
<tr>
<td><form:label path="Country">Date of Join</form:label></td>
<td><form:input path="Country" value="${player.Country }"/></td>
</tr>
<tr>
<td>
<form:label path="teams.teamId">Team Name</form:label>
</td>
<td>
<form:select path="teams.teamId" cssStyle="width: 150px;">
<option value="-1">Select a type</option>
<c:forEach items="${teamKey}" var="teams">
<option value="${teams.teamId}">${teams.teamName}</option>
</c:forEach>
</form:select>
</td>
</tr>
<tr>
<tr>
<td colspan="2"><input type="submit"value="Submit"></td>
</tr>
</table>
</form:form>
<br/>
<c:if test="${!empty playerkey}">
<table align="center" border="1">
<tr>
<th>Player ID</th>
<th>Player Name</th>
<th>YearsActive</th>
<th>Country</th>
</tr>
<c:forEach items="${playerkey}" var="player">
<tr>
<td><c:out value="${player.playerId}"/></td>
<td><c:out value="${player.playerName }"/></td>
<td><c:out value="${player.YearsActive}"/></td>
<td><c:out value="${player.Country}"/></td>
<td align="center">Edit | Delete</td>
</tr>
</c:forEach>
</table>
</c:if>
<h2>Adding Team</h2>
</center>
</body>
</html>
please help.
thanks in advance
For your use case your database modelling ( if you have schema already defined) or entity modelling( in case you are generating schema from your entity model) is incorrect. The foreign key should be on the AddTeam table pointing to the primary key of Player. In terms of entity mappings, the OneToOne should be on the AddTeam.

How to find foreign key references in mysql in spring hibernate annotation

Hi i am writing a spring mvc hibernate annotation application there i have 2 tables "team" and another table "players".Here i am using one-to-one mapping and mysql database.In players table i am keeping player records like name,years active etc.The "team" table contains two entries teamid(primary key)and teamname.
The "players" table contains the foreign key teamid.Here when i try to delete a teamname without deleting all its references in players table i am getting error message
HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query
so when i delete all the references ,then there is no error.So how can i find all the refrences before deleting.I am interested in showing an alert message using javascript which warns to delete all references.I know how to create simple alert message in javascript,but here i have to show the alert only if there is a reference to foreign key.And i want to know is there any alternate way to delete the foriegn key reference without affecting the "players" table.
Team.java
#Entity
#Table(name="Team")
public class AddTeam {
#Id
#Column(name="teamId")
private Integer teamId;
#Column(name="teamName")
private String teamName;
public Integer getTeamId() {
return teamId;
}
public void setTeamId(Integer teamId) {
this.teamId = teamId;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
}
Player.java
#Entity
#Table(name="playerdata")
public class Player implements Serializable {
private static final long serialVersionUID = -723583058586873479L;
/**
*
*/
#Id
#Column(name="playerid")
private Integer playerId;
#Column(name="playername")
private String playerName;
#Column(name="yearsactive")
private Integer yearsActive;
#Column(name="country")
private Integer Country;
#OneToOne
#JoinColumn(name="teamId")
private AddTeam teams;
public Integer getPlayerId(){
return playerId;
}
public void setPlayerId(Integer playerId){
this.playerId=playerId;
}
public String getPlayerName(){
return playerName;
}
public void setPlayerName(String playerName){
this.playerName=playerName;
}
public String getCountry(){
return Country;
}
public void setCountry(String Country){
this.Country=Country;
}
public Integer getyearsActive(){
return yearsActive;
}
public void setyearsActive(Integer yearsActive){
this.yearsActive=yearsActive;
}
public AddTeam getTeams() {
return teams;
}
public void setTeams(AddTeam teams) {
this.teams = teams;
}
}
and this is the query used in playerDaoImplementation.java class
#Override
public void deleteResource(int playerid) {
// TODO Auto-generated method stub
sessionfactory.getCurrentSession().createQuery("DELETE FROM Resource WHERE playerid=" +playerid).executeUpdate();
}
Query used to delete in AddteamDaoImplementation.java
#Override
public void deleteTeams(int teamid) {
// TODO Auto-generated method stub
sessiofactory.getCurrentSession().createQuery("DELETE FROM AddTeam WHERE teamid="+teamid).executeUpdate();
}
deletefunction in PlayerController.java
#RequestMapping(value="/deletePlayer",method=RequestMethod.GET)
public ModelAndView deletePlayerDetails(#ModelAttribute("command") Player player,
BindingResult result){
playerService.deletePlayer(player.getPlayerId());
Map<String, Object> model = new HashMap<String, Object>();
model.put("playerkey", playerService.listPlayer());
model.put("teamKey", addteamService.listTeams());
return new ModelAndView("EditPlayer",model);
}
Team.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Players Manager</title>
<center>
<h2>Add Team Details</h2>
<form:form method="POST" action="Team.html">
<table>
<tr>
<td><form:label path="teamId">Team ID:</form:label></td>
<td><form:input path="teamId" id="demo" value="${team.teamId}"/></td>
</tr>
<tr>
<td><form:label path="teamName">Team Name:</form:label></td>
<td><form:input path="teamName" value="${team.teamName}"/></td>
</tr>
<tr>
<tr>
<td> </td>
<td><input type="submit" value="SAVE"/></td>
</tr>
</table>
</form:form>
<br/>
<c:if test="${!empty teamKey}">
<table align="center" border="1">
<tr>
<th>Category ID</th>
<th>Category Name</th>
<th>Options</th>
</tr>
<c:forEach items="${teamKey}" var="team">
<tr>
<td><c:out value="${team.teamId}"/></td>
<td><c:out value="${team.teamName}"/></td>
<td align="center">Edit |
Delete</td>
</tr>
</c:forEach>
</table>
</c:if>
<h2>Adding Publication</h2>
</center>
</body>
</html>
EditPlayer.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Resource Manager</title>
</head>
<body>
<center>
<h2>Add Players</h2>
<form:form method="POST" action="save.html">
<table>
<tr>
<td><form:label path="playerId">Player Id</form:label></td>
<td><form:input path="playerId" value= "${player.playerId }"/></td>
</tr>
<tr>
<td><form:label path="playerName">Name</form:label></td>
<td><form:input path="playerName" value="${player.playerName }"/></td>
</tr>
<tr>
<td><form:label path="YearsActive">Experience</form:label></td>
<td><form:input path="YearsActive" value="${player.YearsActive }"/></td>
</tr>
<tr>
<td><form:label path="Country">Date of Join</form:label></td>
<td><form:input path="Country" value="${player.Country }"/></td>
</tr>
<tr>
<td>
<form:label path="teams.teamId">Team Name</form:label>
</td>
<td>
<form:select path="teams.teamId" cssStyle="width: 150px;">
<option value="-1">Select a type</option>
<c:forEach items="${teamKey}" var="teams">
<option value="${teams.teamId}">${teams.teamName}</option>
</c:forEach>
</form:select>
</td>
</tr>
<tr>
<tr>
<td colspan="2"><input type="submit"value="Submit"></td>
</tr>
</table>
</form:form>
<br/>
<c:if test="${!empty playerkey}">
<table align="center" border="1">
<tr>
<th>Player ID</th>
<th>Player Name</th>
<th>YearsActive</th>
<th>Country</th>
</tr>
<c:forEach items="${playerkey}" var="player">
<tr>
<td><c:out value="${player.playerId}"/></td>
<td><c:out value="${player.playerName }"/></td>
<td><c:out value="${player.YearsActive}"/></td>
<td><c:out value="${player.Country}"/></td>
<td align="center">Edit | Delete</td>
</tr>
</c:forEach>
</table>
</c:if>
<h2>Adding Team</h2>
</center>
</body>
</html>
please help.
thanks in advance
You have to do select query for teamId in players table to find players and in DB you can put cascade delete in players Table so it will delete players when you delete Team.