In MVC (like JSP and Spring), is it bad practice to view related code in a controller?
In my case, the controller does some work and then passes the results to the view (JSP). In the case of a status message, I can pass the entire text of the message to the view or pass the key and let the JSP match it with the message text.
Example:
The message generated in the controller
Spring Controller:
protected ModelAndView onSubmit(...) {
Map map = new HashMap();
if (...)
map.put("status", "Case 1 status message");
else
map.put("status", "Case 2 status message");
return new ModelAndView("viewPage", map);
}
JSP:
{$status}
Generated message
Spring Controller:
protected ModelAndView onSubmit(...) {
Map map = new HashMap();
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 the JSP code are simpler, but the corresponding logic is visible in the controller. In the second case, all the viewing logic is in the JSP, but the code is not so simple.
Am I breaking the MVC paradigm by generating message text in the controller? What is common practice for this scenario?