Skip to content

Instantly share code, notes, and snippets.

@mathieuancelin
Created February 13, 2012 10:12
Show Gist options
  • Save mathieuancelin/1815755 to your computer and use it in GitHub Desktop.
Save mathieuancelin/1815755 to your computer and use it in GitHub Desktop.
@Path("index")
@Stateless
public class App {
@Inject IndexTemplate index;
@GET @Produces(MediaType.TEXT_HTML)
public IndexTemplate index() {
return index.title("Tasks").addTasks(Task.all);
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>{{title}}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="{{root}}/public/css/style.css" rel="stylesheet" type="text/css" media="screen" />
<script src="{{root}}/public/js/jquery-1.4.4.js" language="javascript" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<div id="header-wrapper">
<div id="header">
<div id="logo">
<h1><a href="{{root}}/res/index">web-framework</a></h1>
<p>the useless web framework</p>
</div>
</div>
</div>
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm">
<div id="content">
<div class="post">
<h2 class="title"><a href="#">Todo list</a></h2>
<div class="entry">
<ul>
{{#tasks}}
<li><input type="checkbox" id="{{id}}" {{isDone}} />{{title}}</li>
{{/tasks}}
</ul>
<p>
<a id="createTask" href="#">Create a new task</a>
</p>
<script type="text/javascript">
$('#createTask').click(function() {
$.post("{{root}}/res/index/createTask", {title: prompt('task title')}, function(task) {
$('ul').prepend(
'<li><input type="checkbox" id="' + task.id + '"/>' + task.title + '</li>'
);
});
});
$('input').live('click', function() {
$.post("{{root}}/res/index/change", {id: $(this).attr('id'), done: $(this).val()})
});
</script>
</div>
<div class="byline" />
</div>
<div style="clear: both;">&nbsp;</div>
</div>
<div style="clear: both;">&nbsp;</div>
</div>
</div>
</div>
</div>
</body>
</html>
@RequestScoped
@Template("index.html")
public class IndexTemplate {
private String title;
private List<Task> tasks;
public IndexTemplate title(String title) {
this.title = title;
return this;
}
public String title() {
return title;
}
public IndexTemplate addTask(Task value) {
if (tasks == null) {
tasks = new ArrayList<Task>();
}
tasks.add(value);
return this;
}
public IndexTemplate addTasks(Collection<Task> value) {
if (tasks == null) {
tasks = new ArrayList<Task>();
}
tasks.addAll(value);
return this;
}
public List<Task> tasks() {
return tasks;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment