I am trying to show the difference in days between two dates of a loan, the request date and the return date, as well as showing with red text, or with a red cell, the loan that has been returned outside of a certain period, in this case 10 days.
My idea is to use a method to which I pass the two dates, it calculates the difference in days and I can display it in a table. I already have the request and return data in a database. In theory the method works.
In the jsp I import the class, build the object and use it in the corresponding cell, I have done it before to convert the dates in the correct format and make the nulls not appear, I have managed everything except changing the color.
I give you the code of the method that I have in a class inside a package called Utilities.
package Utilidades;
import java.util.Date;
public class InformeRetraso {
public String TiempoRetraso(Date fechaDevolucion, Date fechaSolicitud) {
String resultado;
if (fechaDevolucion == null) {
resultado = "sin devolver";
} else {
long diferenciaEnms = fechaDevolucion.getTime() - fechaSolicitud.getTime();
long dias = diferenciaEnms / (1000 * 60 * 60 * 24);
if (dias <= 10) {
resultado = "devuelto en plazo";
} else {
resultado = "devuelto fuera de plazo";
//resultado = Long.toString(dias);
}
//String resultado=dias.toString();
}
return resultado;
}
}
and here the JSP sheet
<%@page import="java.util.List"%>
<%@page import="Entidades.Prestamo"%>
<%@page import="DAO.DAOPrestamo"%>
<%@page import="Utilidades.FechaAFormato"%>
<%@page import="Utilidades.InformeRetraso"%>
<%@page import="Conexion.DBConnection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="prestamo" class="Entidades.Prestamo" />
<jsp:setProperty name="prestamo" property="*"/>
<%
String message = "";
List<Prestamo> prestamos = null;
DAOPrestamo dao = new DAOPrestamo();
FechaAFormato fecha = new FechaAFormato();
InformeRetraso calculo = new InformeRetraso();
try {
prestamos = dao.selectPrestamo();
} catch (Exception ex) {
message = ex.toString();
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>V2formListarPrestamo</title>
<link href="../css/estilos.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="titulo">
<h1>BIBLIOTECA - PRESTAMOS</h1>
<div id="menu">
<div id="opciones">
<h2><a href="../Menu.jsp">Inicio</a></h2>
<h2><a href="V2HojaPrestamos.jsp">Atras</a></h2>
</div>
<form>
<%if (!message.isEmpty()) {%>
<input name="status_initial" type="text" style="width:400px" value="<%=message%>"/>
<%} else { %>
<br/><br/>
<table border="1">
<tr>
<th>id</th>
<th>DNI Usuario</th>
<th>ISBN Obra</th>
<th>Fecha Solicitud</th>
<th>Fecha Devolucion</th>
<th>Retraso</th>
</tr>
<!--creación de una tabla para mostrar todos los objetos prestamo-->
<%
for (int i = 0; i < prestamos.size(); i++) {%>
<tr>
<td><%=prestamos.get(i).getId()%></td>
<td><%=prestamos.get(i).getDNIusuario()%></td>
<td><%=prestamos.get(i).getISBNobra()%></td>
<td><%=fecha.FechaATexto(prestamos.get(i).getFechasolicitud())%></td>
<td><%=fecha.FechaATexto(prestamos.get(i).getFechadevolucion())%></td>
<td><%=calculo.TiempoRetraso(prestamos.get(i).getFechadevolucion(), prestamos.get(i).getFechasolicitud())%></td>
</tr>
<%}%>
</table>
<%}%>
</form>
</div>
</div>
</body>
The idea is that in the last column that is created, the request and return values are passed to the function, they are subtracted and displayed.
This is how it looks right now, what I'm looking for I expose it below.
What I want to achieve is that, depending on the value, the message that I show now is displayed, but if the return date is unreturned, it should be in yellow, if it is returned within the term in green and after the term with a text color in red, for example.
Fixed, the way was to add Jquery so that cells with certain values change to a certain color, I add the code.