Created
November 10, 2013 20:22
-
-
Save taywils/7403433 to your computer and use it in GitHub Desktop.
spark_blog_step_3_1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get(new Route("/article/update/:id") { | |
@Override | |
public Object handle(Request request, Response response) { | |
Integer id = Integer.parseInt(request.params(":id")); | |
StringBuilder form = new StringBuilder(); | |
for(Article article : HelloSpark.articles) { | |
if(id.equals(article.getId())) { | |
form.append("<form id='article-create-form' method='POST' action='/article/update/:id'>") | |
.append("Title: <input type='text' name='article-title' value='").append(article.getTitle()).append("' />") | |
.append("<br/>") | |
.append("Summary: <input type='text' name='article-summary' value='").append(article.getSummary()).append("' />") | |
.append("<input type='hidden' name='article-id' value='").append(article.getId().toString()).append("' />") | |
.append("<br/>") | |
.append("</form>") | |
.append("<textarea name='article-content' rows='4' cols='50' form='article-create-form'>").append(article.getContent()) | |
.append("</textarea>") | |
.append("<br/>") | |
.append("<input type='submit' value='Update' form='article-create-form' />"); | |
break; | |
} | |
} | |
return form.toString(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment