Skip to content

Instantly share code, notes, and snippets.

@rcaneppele
Created May 29, 2014 21:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcaneppele/65b4a908e613d462de61 to your computer and use it in GitHub Desktop.
Save rcaneppele/65b4a908e613d462de61 to your computer and use it in GitHub Desktop.
FJ21-Tarefas - Bootstrap
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<td>
${tarefa.id}
</td>
<td>
${tarefa.descricao}
</td>
<td>
<c:if test="${tarefa.finalizado eq false}">
<a href="#" onclick="finalizaAgora(${tarefa.id})">Finalizar</a>
</c:if>
<c:if test="${tarefa.finalizado eq true}">
Finalizado
</c:if>
</td>
<td>
<fmt:formatDate value="${tarefa.dataFinalizacao.time}" pattern="dd/MM/yyyy"/>
</td>
<td>
<a href="mostraTarefa?id=${tarefa.id}">
<span class="label label-warning">Alterar</span>
</a>
<a href="removeTarefa?id=${tarefa.id}" class="link-remover">
<span class="label label-danger">Remover</span>
</a>
</td>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ 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=UTF-8">
<title>FJ21 - Tarefas</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<form action="efetuaLogin" method="post" class="form-horizontal">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">FJ21-Tarefas - Login</h3>
</div>
<div class="panel-body">
<div class="form-group">
<label for="login" class="col-sm-2 control-label">Login</label>
<div class="col-sm-10">
<input id="login" name="login" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="senha" class="col-sm-2 control-label">Senha</label>
<div class="col-sm-10">
<input type="password" id="senha" name="senha" class="form-control" />
</div>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!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=UTF-8">
<title>FJ21 - Tarefas</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="resources/css/jquery.css" />
<script type="text/javascript" src="resources/js/jquery.js"></script>
<script type="text/javascript" src="resources/js/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
$(".data").datepicker({dateformat: "dd/mm/yy", changeMonth: true, changeYear: true});
});
</script>
</head>
<body>
<c:import url="/WEB-INF/views/menu.jsp"/>
<div class="container">
<c:url var="url" value="${empty tarefa.id ? 'adicionaTarefa' : 'alteraTarefa'}"/>
<form action="${url}" method="post" class="form-horizontal">
<input type="hidden" name="id" value="${tarefa.id}" />
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<c:if test="${empty tarefa.id}">
Cadastro de Tarefa
</c:if>
<c:if test="${not empty tarefa.id}">
Alterar tarefa - ${tarefa.id}
</c:if>
</h3>
</div>
<div class="panel-body">
<div class="form-group">
<label for="descricao" class="col-sm-2 control-label">Descrição</label>
<div class="col-sm-4">
<textarea id="descricao" name="descricao" class="form-control">${tarefa.descricao}</textarea>
</div>
<div class="col-sm-4">
<form:errors path="tarefa.descricao" cssClass="alert alert-danger" element="div" />
</div>
</div>
<c:if test="${not empty tarefa.id}">
<div class="form-group">
<label class="col-sm-2 control-label">Finalizado?</label>
<div class="col-sm-4">
<div class="checkbox">
<input type="checkbox" name="finalizado" value="true" ${tarefa.finalizado? 'checked' : ''} />
</div>
</div>
</div>
<div class="form-group">
<label for="data-finalizacao" class="col-sm-2 control-label">Data de finalização</label>
<div class="col-sm-4">
<input id="data-finalizacao" name="dataFinalizacao" class="form-control data" value="<fmt:formatDate value="${tarefa.dataFinalizacao.time}" pattern="dd/MM/yyyy" />"/>
</div>
</div>
</c:if>
</div>
</div>
<div class="well">
<button type="submit" class="btn btn-primary">Gravar</button>
<a href="listaTarefas" class="btn btn-default">Cancelar</a>
</div>
</form>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ 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=UTF-8">
<title>FJ21 - Tarefas</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<script type="text/javascript" src="resources/js/jquery.js"></script>
<script type="text/javascript">
function finalizaAgora(id) {
$.post("finalizaTarefa", {'id' : id}, function(retorno) {
$("#tarefa_"+id).html(retorno);
bindClickRemover();
});
}
function bindClickRemover() {
$(".link-remover").click(function() {
return confirm("Confirma a remoção?");
});
}
$(bindClickRemover);
</script>
</head>
<body>
<c:import url="/WEB-INF/views/menu.jsp"/>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Tarefas Cadastradas</h3>
</div>
<div class="panel-body">
<a href="novaTarefa" class="btn btn-primary">Criar nova tarefa</a>
<br/><br/>
<table class="table table-bordered table-striped table-hover">
<tr>
<th>Id</th>
<th>Descrição</th>
<th>Finalizado?</th>
<th>Data de finalização</th>
<th>Ações</th>
</tr>
<c:forEach items="${tarefas}" var="tarefa">
<tr id="tarefa_${tarefa.id}">
<td>
${tarefa.id}
</td>
<td>
${tarefa.descricao}
</td>
<td>
<c:if test="${tarefa.finalizado eq false}">
<a href="#" onclick="finalizaAgora(${tarefa.id})">Finalizar</a>
</c:if>
<c:if test="${tarefa.finalizado eq true}">
Finalizado
</c:if>
</td>
<td>
<fmt:formatDate
value="${tarefa.dataFinalizacao.time}"
pattern="dd/MM/yyyy"/>
</td>
<td>
<a href="mostraTarefa?id=${tarefa.id}">
<span class="label label-warning">Alterar</span>
</a>
<a href="removeTarefa?id=${tarefa.id}" class="link-remover">
<span class="label label-danger">Remover</span>
</a>
</td>
</tr>
</c:forEach>
</table>
</div>
</div>
</div>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<ul class="nav navbar-nav">
<li><a href="listaTarefas">Tarefas</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Logado como: ${usuarioLogado.login}</a></li>
<li><a href="logout">Sair</a></li>
</ul>
</div>
</div>
package br.com.caelum.tarefas.controller;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import br.com.caelum.tarefas.dao.JdbcTarefaDao;
import br.com.caelum.tarefas.modelo.Tarefa;
@Controller
public class TarefasController {
@Autowired
private JdbcTarefaDao dao;
@RequestMapping("listaTarefas")
public String lista(Model model) {
model.addAttribute("tarefas", dao.lista());
return "tarefa/lista";
}
@RequestMapping("novaTarefa")
public String form() {
return "tarefa/formulario";
}
@RequestMapping("adicionaTarefa")
public String adiciona(@Valid Tarefa tarefa, BindingResult result) {
if(result.hasFieldErrors("descricao")) {
return "tarefa/formulario";
}
dao.adiciona(tarefa);
return "redirect:listaTarefas";
}
@RequestMapping("mostraTarefa")
public String mostra(Long id, Model model) {
model.addAttribute("tarefa", dao.buscaPorId(id));
return "forward:novaTarefa";
}
@RequestMapping("alteraTarefa")
public String altera(Tarefa tarefa) {
dao.altera(tarefa);
return "redirect:listaTarefas";
}
@RequestMapping("removeTarefa")
public String remove(Tarefa tarefa) {
dao.remove(tarefa);
return "redirect:listaTarefas";
}
@RequestMapping("finalizaTarefa")
public String finaliza(Long id, Model model) {
dao.finaliza(id);
model.addAttribute("tarefa", dao.buscaPorId(id));
return "tarefa/finalizada";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment