Accessing a model attribute in an IMessageResolver

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing a model attribute in an IMessageResolver

digitalbreed
I'm using thymeleaf-1.0.0-beta1. I've implemented an own IMessageResolver and need some meta-information from the model which I've passed into a ModelAndView object before rendering the template.

It's not in the local variable scope, so accessing it with Arguments.getLocalVariable doesn't work. Instead, I am currently accessing the attribute like so:

Map<String,Object> context = (Map<String,Object>) arguments.getExpressionEvaluationRoot();
String value = (String) context.get("key");

This looks quite ugly to me, particularly due to the fact that the evaluationRoot is stored as an Object.

Could you please advise what would be the proper way in Thymeleaf to access a global model attribute in an IMessageResolver?

Regards
db
Reply | Threaded
Open this post in threaded view
|

Re: Accessing a model attribute in an IMessageResolver

danielfernandez
Administrator
Hi,

I might not be correctly understanding your problem -- sorry for that -- but... if you want to access a context variable (= model attribute), why not use the arguments.getContext() method?

IContext ctx = arguments.getContext();
Object myVar = ctx.getVariables().get("key");

...wouldn't you be able to retrieve your attribute from there?

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing a model attribute in an IMessageResolver

digitalbreed
Sorry for not seeing the obvious. Thanks for your prompt response.