Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

JAVA - Next and Back button on html with arrayList


  • Please log in to reply

#1
Raptiler

Raptiler

    New Member

  • Member
  • Pip
  • 1 posts
So i'm having this problem that i have no idea how to do it. I hope you can help me out on this one. I want to make a NEXT\PREVIOUS button that only shows 20 items from an arraylist and then the next 20 and so on...
The code i have is:

(RECORDSARRAY)
public class ArrayRecords{
private int id;
private String service;
private String technician;
private String state;
private String startDate;
private String endDate;
private String startTime;
private String endTime;
private String description;
private String priority;
GETTERS AND SETTER ; AND THE CONSTRUCTORS USING FIELDS.

(ConnectionDB)

public ArrayList <ArrayRecords> showList(){
ArrayList<ArrayRecords> recordList= null;
ArrayRecords arrayRecords=null;
if (connection != null) {
try{
recordList= new ArrayList<ArrayRecords>();
Statement statement = connection.createStatement();
String query=String.format("SELECT Registos.id,nomeServico,nomeTecnico,estado,dataInicio,dataFim,horaInicio,horaFim,descricao,prioridade FROM Servicos,Tecnicos,Estados,Registos WHERE servicos_id=Servicos.id and tecnicos_id=Tecnicos.id and estados_id=Estados.id");
ResultSet rs = statement.executeQuery(query);
while (rs.next()) {
arrayRecords= new ArrayRecords (rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10));
recordList.add(arrayRecords);
}
}catch(SQLException ex){
ex.printStackTrace();
}
}

return recordList;
}
(SERVLET)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

ConnectionDB connectionDB = new connectionDB();
ArrayList<ArrayRecords> recordList;
recordList= connectionDB .showList();

request.setAttribute("recordList",recordList);

RequestDispatcher view = request.getRequestDispatcher("recordList.jsp");
vista.forward(request, response);
}
(JSP)

<%
ArrayList<ArrayRecords> recordList= (ArrayList<ArrayRecords>) request.getAttribute("recordList");
if (recordList.size() == 0) {

out.println("<h2>No Records</h2>");
%><%
} else {%><%
out.println("<table id=\"myTable\" border=3 width=\"1100\"height=\"1\">");
out.println("<thead>");
out.println("<tr>");
out.println("<center><td>Estado</td><td>Data Início</td><td>Hora Início</td><td>Técnico</td><td>Serviço</td><td>Descricao</td><td>Data Fim</td><td>Hora Fim</td></center>");
out.println("</tr>");
out.println("</thead>");
out.println("<tbody>");
for (ArrayRecords i : recordList) {
if(i.getState().equals("Pendente")){
out.println("<tr class=\"pendente\">");
out.println("<td>");
out.println(String.format("<center><a href=\"Detail?details="+i.getId()+"\"><span id=\"cor\" style=\"color: red ;\">"+i.getState()+"</span></a></center>"));
}else if(i.getState().equals("Concluído")){
out.println("<tr class=\"concluido\">");
out.println("<td>");
out.println(String.format("<center><a href=\"Detail?details="+i.getId()+"\"><span id=\"cor\" style=\"color: green ;\">"+i.getState()+"</span></a></center>"));
}else if(i.getState().equals("Validado")){
out.println("<tr class=\"validado\">");
out.println("<td>");
out.println(String.format("<center><a href=\"Detail?details="+i.getId()+"\"><span id=\"cor\" style=\"color: blue ;\">"+i.getState()+"</span></a></center>"));
}
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getStartDate()+"</center>"));
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getStartTime()+"</center>"));
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getTechnician()+"</center>"));
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getService()+"</center>"));
out.println("</td>");
out.println("<td>");
String description = i.getDescription();
if (description !=null && description .length()> 60){

out.println("</span>");
description =description .substring(0,40);
out.println("<center><span class=\"dropt\" title=\"\">"+descricao+"...</center>");
out.println("<span style=\"color: black ;\">"+i.getDescricao()+"</span>");

}else if(description ==null){
description ="No description";
out.println(String.format("<center>"+description+"</center>"));
}else if(description.isEmpty()){
description ="No description";
out.println(String.format("<center>"+description+"</center>"));

}else{
out.println(String.format("<center>"+i.getDescription()+"</center>"));
}
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getEndDate()+"</center>"));
out.println("</td>");
out.println("<td>");
out.println(String.format("<center>"+i.getEndTime()+"</center>"));
out.println("</td>");
out.println("</tr>");



}
out.println("</tbody>");
out.println("</table>");



}
//}
%>


The image shows the table, which is being sucessfully created with this code i posted here. but i wanted to show only 20 of the records, then have a next button to give the next 20 records. bcuz if the SQL table get's more crowded it will grow and it will be painfull to the user to scroll down...
I hope i explained myself.
And i hope for some help :) plz...

Attached Thumbnails

  • tab.JPG

  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP