jpa - Dynamically loading data according to a session attribute -



jpa - Dynamically loading data according to a session attribute -

i'm trying dynamically load dataset accordingly user session attribute, inject , set parameter in namedquery.

the namedquery works fine, i'm not getting dataset desired.

i mean, when session attribute 9882, dataset loaded corresponds findall query. but, in meantime, if user logs in app - , session attribute 4207 - dataset stills same 9882, means dataset still correspond findall query; , vice-versa: if 1st session attribute 4207, uses findbyprefdep query, expected, dataset still same 9882 session attribute logged after 4207 user.

@inject private string sessionprefdep; public collection<t> getitems() { if (items == null) { if (integer.valueof(sessionprefdep) == 4207) { items = this.ejbfacade.findbyprefdep(); } else if (integer.valueof(sessionprefdep) == 9882) { items = this.ejbfacade.findall(); } } homecoming items; }

does knows how can accomplish desired control?

thanks in advance.

----------- new section

the producer:

@applicationscoped public class beancdi { private final string sessionprefdep = (string) facescontext.getcurrentinstance().getexternalcontext().getsessionmap().get("xprefdep"); @produces public string sessionprefdep() { homecoming sessionprefdep; } }

the controller:

@inject private instance<string> sessionprefdep; public collection<t> getitems() { int sessionid = integer.valueof(sessionprefdep.get()); if ((items == null) && (sessionid == 4207)) { items = this.ejbfacade.findbyprefdep(); system.out.print("****************** findbyprefdep() - sessionid:" + sessionid); } else if ((items == null) && (sessionid == 9882)) { items = this.ejbfacade.findall(); system.out.print("****************** findall() - sessionid:" + sessionid); } homecoming items; }

you can via

@inject private instance<string> sessionprefded; //then in code int sesionid = integer.valueof(sessionprepdef.get());

this way should fresh value. depends how create object, far remember can inject strings in cdi producers.

session jpa cdi

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -