I have a controller with two render methods that take different arguments:
class MyController
{
@RenderMapping
public void render(@ModelAttribute ClassX param)
{
// do some stuff
}
@RenderMapping
public void render2(@ModelAttribute ClassY param)
{
// do different stuff
}
}
Of course what is missing in the example above is some specification for spring to know which of the render methods to invoke. I need to decide this based on a state stored in the current session. I can’t specify this just as a simple annotation, can I?
An alternative idea is something like this:
class MyController2
{
@RenderMapping
public void render(RenderRequest request)
{
if (request.getPortletSession().getAttribute(...) ...)
{
ClassX param = retrieveObjectFromRequest(ClassX.class, request);
// do some stuff
}
else
{
ClassY param = retrieveObjectFromRequest(ClassY.class, request);
// do different stuff
}
}
}
But in this case… How do I implement the retrieveObjectFromRequest method?
OK, after scrolling Spring’s source code for a while I figured a way to do the retrieveObjectFromRequest part: