I am using Spring MVC application and I have a JSP with following code.
<c:choose>
<c:when test="${type eq 'school'}">
<h1 class="title">${schoolVO.name}</h1>
</c:when>
<c:when test="${type eq 'college'}">
<h1 class="title">${collegeVO.name}</h1>
</c:when>
<c:when test="${type eq 'tution'}">
<h1 class="title">${tutionVO.name}</h1>
</c:when>
...
..
..
Many other types...
</c:choose>
This jsp is called when there is a method in controller which depend on the type
set the model attribute .
If the type is school , it puts
modelMap.addAttribute("schoolVO", school);
if college then
modelMap.addAttribute("collegeVO", college);
Similarly others..
Now i want to remove this <c:when> conditions in jsp.
Now depending upon the type I want to add one model attribute and put either
schoolVO or collgeVO like
modelMap.addAttribute("typeVO", "schoolVO");
So that I did not need to use if <c:when> conditions in jsp .
And I want to use something like
${{typeVO}.name}
But this gives me error
contains invalid expression(s): javax.el.ELException: Error Parsing:
How i can achieve this?
Thanks in advance.
P.S. I could not get the proper title for my question. Please change it if there is something appropriate i can put.
You can complicate yourself having lots of different attributes set in the request. AFAIK, it would be better to have a single attribute that handles the name you want to print:
That contains the title you will print, then in your JSP you don’t have use any validation, just write