I'm using SAP Hybris 1811 on my local machine. I've got custom error page handler in web.xml
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/errors</location>
</error-page>
And a controller for handling this error (note it's not extending AbstractPageController
, for reason read further)
@Controller
public class ErrorController {
@RequestMapping(value = "/errors", method = RequestMethod.GET)
public ModelAndView handleErrors(Model model, HttpServletRequest httpRequest) {
httpRequest.getLocale();
.... some code here
}
}
I need to get correct current locale
of the app for displaying correct language in error page, but it's still getting only English, although it should be other language.
I tried to load i18nService
and it's locale for example like this, but it's still "en":
SpringHelper.getSpringBean(httpRequest, "i18nService", DefaultI18NService.class, true).getCurrentLocale()
I thought the problem was because of the ErrorController
doesn't extend AbstractPageController
, but when I tried that, none of the error methods could be reached.
In the end I was able to get the correct locale like this:
Locale loc = ((Locale)((CommerceJaloSession)this.pageContext.getSession().getAttribute("jalosession")).getAttribute("locale"));