1

So, it's better to pass the Locale to EJB via parameter, instead of get it myself from FacesContext;

Now, if I do use this parameter in every method, whats a good approach to set it only once?

I don't like the idea of a setLocale() method; I would like to force it to be set, with some compilation error (instead of seeing the error only later at runtime).

For this answer, looks like I can't use construtor parameter. The idea of setting the attribute in the request is nice, but the only way I know to get the request object is via FacesContext, what, again, we don't want the FacesContext dependency inside the EJB.

Is there some way to force the developer to pass the Locale for the EJB? I mean, if not set, generate a compilation error?

Community
  • 1
  • 1
The Student
  • 27,520
  • 68
  • 161
  • 264
  • What's the business of having `Locale` in backend? This is certainly worring given that it appears to be a frontend-managed one. Perhaps the task you had in mind with the `Locale` actually belongs in the frontend? – BalusC Jun 01 '16 at 19:58
  • @BalusC I'll e-mail the client if the task succeed. And I have the e-mail texts in a `.properties` file. And to load that properties file I need the Locale. I was, just now, thinking about load the ResourceBundle and pass it to the EJB, instead of the Locale... But the question about how to force it to be passed continues (passing a single time, not in every single method). – The Student Jun 01 '16 at 21:25
  • So, there's a logged-in user and it's actually the user's preferred locale? When using container managed security, the logged-in user is just directly available in EJBs too. – BalusC Jun 01 '16 at 21:30
  • @BalusC but I need the `.properties` data, not the logged-in user's. – The Student Jun 02 '16 at 14:29
  • I was talking about the locale. Is it actually the user's preferred locale or not? – BalusC Jun 02 '16 at 14:30
  • @BalusC yes! Right. This answer the specific question, although I still would like to know how to set something to the EJB, with a compilation error if that was not set. – The Student Jun 02 '16 at 16:13
  • 1
    Service layer can't expect that from its client. Way too fishy. If you want statefulness, use a stateful EJB injected in an application scoped managed bean, or use a singleton EJB. – BalusC Jun 02 '16 at 16:16

0 Answers0