In MVC (such as JSP and Spring), is it bad practice to view related code in the controller?
In my case, the controller does some work and then hands off the results to the view (JSP). In the case of a status message, I can pass the entire message text to the view, or pass a key and let the JSP map it to the message text.
Example:
Message generated in controller
Spring Controller:
protected ModelAndView onSubmit(...) {
Map map = new HashMap();
// Controller processing
if (...)
map.put("status", "Case 1 status message");
else
map.put("status", "Case 2 status message");
return new ModelAndView("viewPage", map);
}
JSP:
{$status}
Message generated in view
Spring Controller:
protected ModelAndView onSubmit(...) {
Map map = new HashMap();
// Controller processing
if (...)
map.put("status", "case1");
else
map.put("status", "case2");
return new ModelAndView("viewPage", map);
}
JSP:
<c:choose>
<c:when test="{$status eq 'case1'}">Case 1 status message</c:when>
<c:when test="{$status eq 'case2'}">Case 2 status message</c:when>
</c:choose>
In the first case, the controller and JSP code is simpler, but there's view related logic in the controller. In the second case, all view logic is in the JSP, but the code isn't as simple.
Am I violating MVC paradigm by generating message text in the controller? What is the common practice for this scenario?