2

Would it be better, for example, to pass context.getExternalContext().getRequestLocale() to the EJB by parameter, instead of using an import and getCurrentInstance from inside the EJB?

import javax.faces.context.FacesContext;
FacesContext.getCurrentInstance()

(I'm new to web development)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
The Student
  • 27,520
  • 68
  • 161
  • 264
  • see [Why is it a good idea for “lower” application layers not to be aware of “higher” ones?](http://programmers.stackexchange.com/q/198783/7460) – Nathan Hughes May 31 '16 at 19:36
  • @NathanHughes I'll read (and I think it is a good idea). But is it the context a higher layer? I thing about the context as a side layer that everyone knows about. – The Student May 31 '16 at 19:42
  • Possible duplicate of [why shouldn't entity bean be managed by JSF framework?](http://stackoverflow.com/questions/25431338/why-shouldnt-entity-bean-be-managed-by-jsf-framework) – BalusC Jun 01 '16 at 20:02

1 Answers1

4

If you think of your software system as a three layer architecture then the FacesContext (which is part of the JSF framework) belongs to the presentation layer and the EJB to the application layer.

In general it's bad software design when a lower layer (application) depending on higher layer (Presentation). It leads to high coupling, low cohesion and therefore overall to poor software quality.

To sum it up, it would be better to pass the values by parameter instead of accessing the FacesContext from a EJB.

Paul Wasilewski
  • 9,762
  • 5
  • 45
  • 49