Commit 2f84cdc7 authored by Phillip Webb's avatar Phillip Webb

Merge pull request #4735 from dubu/dubu0.1

* pr/4735:
  Add update/delete to the web-ui sample
parents ffbdfc58 0de4b6ce
......@@ -50,4 +50,9 @@ public class InMemoryMessageRepository implements MessageRepository {
return this.messages.get(id);
}
@Override
public void deleteMessage(Long id) {
this.messages.remove(id);
}
}
......@@ -24,4 +24,6 @@ public interface MessageRepository {
Message findMessage(Long id);
void deleteMessage(Long id);
}
......@@ -30,6 +30,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/**
* @author Rob Winch
* @author Doo-Hwan Kwak
*/
@Controller
@RequestMapping("/")
......@@ -73,4 +74,16 @@ public class MessageController {
throw new RuntimeException("Expected exception in controller");
}
@RequestMapping(value = "delete/{id}")
public ModelAndView delete(@PathVariable("id") Long id) {
this.messageRepository.deleteMessage(id);
Iterable<Message> messages = this.messageRepository.findAll();
return new ModelAndView("messages/list", "messages", messages);
}
@RequestMapping(value = "modify/{id}", method = RequestMethod.GET)
public ModelAndView modifyForm(@PathVariable("id") Message message) {
return new ModelAndView("messages/form", "message", message);
}
}
......@@ -26,6 +26,10 @@
Messages
</a>
</div>
<input type="hidden"
th:field="*{id}"
th:class="${#fields.hasErrors('id')} ? 'field-error'"
/>
<label for="summary">Summary</label>
<input type="text"
th:field="*{summary}"
......@@ -35,7 +39,7 @@
th:field="*{text}"
th:class="${#fields.hasErrors('text')} ? 'field-error'"></textarea>
<div class="form-actions">
<input type="submit" value="Create"/>
<input type="submit" value="Save"/>
</div>
</form>
</div>
......
......@@ -37,6 +37,17 @@
A detailed message that is longer than the summary.
</dd>
</dl>
<div class="pull-left">
<a href="messages"
th:href="@{'/delete/' + ${message.id}}">
delete
</a>
|
<a href="form.html"
th:href="@{'/modify/' + ${message.id}}">
modify
</a>
</div>
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment