I have SessionScoped bean called userSession to keep track of the user ( username, ifLogged, etc). I want to filter some pages and therefore I need to access the bean from the webFilter I created. How do I do that? I looks like its even impossible to import the bean to be potenitally visible.
相关问题
- java.lang.NullPointerException at java.io.PrintWri
- h:selectOneMenu in p:dataTable doesn't submit
- PrimeFaces block UI does not work when the compone
- primefaces orderlist not getting updated with the
- JSF2 composite cc.attrs expression does not evalua
相关文章
- How to allow numbers only using f:validateRegex
- JSF 2.0: ajax request when press ENTER
- Formatting a double in JSF
- change rendered attribute from managed bean
- f:convertNumber on Double: ClassCastException
- SeamPhaseListener - Could not start transaction -
- How do I access EJB bean when inside a custom Conv
- Getting value from dynamically created inputText
As an alternative you can use CDI-beans and inject your sessionbean normally.
Under the covers, JSF stores session scoped managed beans as an attribute of the
HttpSession
with the managed bean name as key.So, provided that you've a
@ManagedBean @SessionScoped public class User {}
, just this should do inside thedoFilter()
method:Or, if you're actually using CDI instead of JSF to manage beans, then just use
@Inject
directly in the filter.See also: