blong824
blong824

Reputation: 4030

Pass Session Variable to MessageSource

I have a controller that shows a form and loads messages from a properties file. I extended ReloadableResourceBundleMessageSource and called it DatabaseMessageSource. Now if there is a message in the database it will get that and if not default to what is in the proeprties file. Link to example

My database lookup is called like getCode(companyId, code). To make the above example work I just passed a 1 for companyId.

I would like to pass the companyId that is in session to the DatabaseMessageSource so it can pull the right messages for that particular company. Does anyone know how I can accomplish this?

Upvotes: 0

Views: 487

Answers (1)

skaffman
skaffman

Reputation: 403501

You can obtain the current HttpSession at any point using this:

ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
HttpSession session = attr.getRequest().getSession(); 

Then get your attribute from there.

Upvotes: 2

Related Questions