Skip to content

Instantly share code, notes, and snippets.

@darbyluv2code
Created June 28, 2017 18:21
Show Gist options
  • Select an option

  • Save darbyluv2code/7e19faf7cfcdf9accf88d086864f1224 to your computer and use it in GitHub Desktop.

Select an option

Save darbyluv2code/7e19faf7cfcdf9accf88d086864f1224 to your computer and use it in GitHub Desktop.
Sort by Clicking Table Header/Column
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix= "fmt" %>
<!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>List Customers</title>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/style.css ">
<!--<link href="<c:url value='/resources/css/style.css' />" rel="stylesheet">-->
<style>
a { color: black; }
</style>
</head>
<body>
<div id="wrapper">
<div id="header">
<h2>CRM - Customer Relationship Manager</h2>
</div>
<div id="container">
<div id="content">
<!-- put new button:Add new customer -->
<!-- showFormForAdd is the value that is being send to customer controller -->
<input type="button" value="Add Customer"
onclick="window.location.href='showFormForAdd'; return false;"
class="add-button"
/>
<!-- add our html table here -->
<table>
<tr>
<th>
<a href="${pageContext.request.contextPath}/customer/list?thesortfield=firstName">
First Name
</a>
</th>
<th>
<a href="${pageContext.request.contextPath}/customer/list?thesortfield=lastName">
Last Name
</a>
</th>
<th>
<a href="${pageContext.request.contextPath}/customer/list?thesortfield=email">
Email
</a>
</th>
<th>
<a href="${pageContext.request.contextPath}/customer/list?thesortfield=dateOfBirth">
Date of an Appointment
</a>
</th>
<th>
<a href="${pageContext.request.contextPath}/customer/list?thesortfield=dateOfBirth">
Time of an Appointment
</a>
</th>
</tr>
<!-- loop over and print our customers -->
<c:forEach var="tempCustomer" items="${ customers}">
<tr>
<!-- firstName is name of customer field not database field etc -->
<td>${tempCustomer.firstName }</td>
<td>${tempCustomer.lastName }</td>
<td>${tempCustomer.email }</td>
<!-- <td>${tempCustomer.dateOfBirth }</td>-->
<td><fmt:formatDate type="date" dateStyle="medium" timeStyle="medium" value="${tempCustomer.dateOfBirth}" /></td>
<td><fmt:formatDate type="time" dateStyle="medium" timeStyle="medium" pattern="HH:mm" value="${tempCustomer.dateOfBirth}" /></td>
<!-- pattern="HH:mm:ss" -->
</tr>
</c:forEach>
</table>
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment