public void createByUserId(RequestContext rc) throws IOException, ServletException
{
HttpServletRequest request = rc.getRequest();
HttpServletResponse response = rc.getResponse();
User user = _userDao.get(Long.valueOf(rc.getPathElement(1)));
if(user==null)
{
response.sendError(404);
return;
}
Todo todo = null;
try
{
todo = (Todo)rc.getConsumer().consume(rc);
}
catch(ValidationException ve)
{
request.setAttribute(Constants.MSG, ve.getMessage());
request.setAttribute(Constants.ACTION, Constants.ACTION_CREATE);
dispatchToFormView((Todo)ve.getPojo(), rc, getWebContext());
return;
}
todo.setUser(user);
boolean created = _todoDao.create(todo);
if(created)
{
/*request.setAttribute(Constants.MSG, Feedback.TODO_CREATED.getMsg());
request.setAttribute(Constants.USER, user);
response.setContentType(Constants.TEXT_HTML);
getWebContext().getJSPDispatcher().dispatch("users/id.jsp",
request, response);*/
response.sendRedirect(request.getContextPath() + "/users/" + user.getId() + "/todos");
}
else
{
request.setAttribute(Constants.MSG, Feedback.COULD_NOT_CREATE_TODO.getMsg());
request.setAttribute(Constants.ACTION, Constants.ACTION_CREATE);