Criando uma lista na sessão com DWR – Parte 3
Na parte 3 do nosso artigo vamos ver que tipos de métodos iremos criar no nosso FacadeAjaxSession explicado no artigo anterior.
Agora veremos os trechos dos novos métodos:
Método para adicionar um objeto na sessão:
public void addMapSession(BeanSession beanSession){ Session session = new SessionFacade();//01 Map<String, BeanSession> sessionMap = null;//02 if(session.getAttribute("sessionMap") != null){ //03 sessionMap = (Map) session.getAttribute("sessionMap");//04 }else{ sessionMap = new HashMap<String, BeanSession>();//05 } String keyMap = beanSession.getId() + "_" + beanSession.getName();//06 beanSession.setKeyMap(keyMap); //07 sessionMap.put(keyMap, beanSession); //08 session.setAttribute("sessionMap", sessionMap); //09 }
Listagem 03: Método que adiciona em um atributo da sessão o objeto passado como parâmetro.
Na listagem 03 vimos o método addMapSession() que espera como parâmetro um BeanSession(ver listagem 01), veja baixo:
01:Criamos o objeto session a partir de nossa classe SessionFacade;
02:Criamos um Map(sessionMap);
03: Recuperamos da sessão o atributo utilizado, e verificamos se o mesmo já existe;
04:Caso o Atributo exista(linha 03) pegamos o valor desse atributo e adicionamos no Map(sessionMap);
05:Caso o atributo não exista inicializamos o sessionMap;
06:Criamos uma variável que servirá como identificador do objeto, que será utilizado no lado JavaScript para identificar o objeto que o usuário está clicando. OS: Como não estou utilizando dados de um banco, tive que fazer essa “adaptação” para simular o id. O que eu fiz foi nada mais que garantir que o objeto que estou inserindo neste momento não terá o mesmo id do próximo;
07:Adiciono esse keyMap(identifica o mapa, linha 06) no meu BeanSession;
08:Adiciono no sessionMap a chave do meu mapa(keyMap) e o meu objeto(BeanSession).
Método para listar um objeto na sessão:
public Map listMapSession() throws Throwable { Session session = new SessionFacade(); Map<String, BeanSession> sessionMap = null; if (session.getAttribute("sessionMap") != null) { sessionMap = (Map) session.getAttribute("sessionMap"); } else { sessionMap = new HashMap<String, BeanSession>(); } return sessionMap; }
Listagem 04: Método que retorna um Map da sessão.
Este método dispensa explicação mais detalhada, ele apenas retorna um Map que está salvo em um determinado atributo na sessão.
Método para excluir um objeto da sessão:
public void removeValueMap(BeanSession beanSession) throws Throwable { Session session = new SessionFacade(); Map sessionMap = null; if (session.getAttribute("sessionMap") != null) { sessionMap = (Map) session.getAttribute("sessionMap"); } else { sessionMap = new HashMap<String, BeanSession>(); } if (sessionMap.containsKey(beanSession.getKeyMap())) { sessionMap.remove(beanSession.getKeyMap()); } session.setAttribute("sessionMap", sessionMap); }
Listagem 05: Método que exclui o objeto passado como parâmetro da sessão.
Um método também bem simples. Recebe o objeto como parâmetro, recupera o valor da sessão, verifica se existe um objeto no Map através da chave (keyMap), caso exista ele remove o objeto do Map e adiciona novamente o Map na sessão.
São métodos simples e claro precisam de mais alguns requintes, mas, esse não é o objetivo do nosso artigo. Quero apenas exemplificar essa funcionalidade.
No próximo artigo(parte 4) iremos ver a implementação no lado JavaScript.
Abraços
darknet drug links dark market 2023
dark web search engines darknet markets
Helpful info. Ꮮucky mme І discovered your web sitе unintentionally, and I’m shoсked
why this coіncidence didn’t came about eaгlier!
Ӏ bookmarked it.
Also vіsit mmy blog; game sigma battle royale mod apk
blackweb official website dark web sites
dark market onion deep dark web
Thanks a buncһ for sharing tis with all folks yoⲟu really understɑnd what yⲟu are
speaking aЬout! Bookmarked. Kіndly additionally talk over with
my site =). We will have а link exchange agreement between us
Heere is my weƄрage … american
tor marketplace deep web search
darkmarket list onion market
hell᧐!,I lovee your writing very so much! share we be іn contact
more approximately your post on AOL? I require a sрecilist in this house to ᥙnraveⅼ
my proЬlem. Maybe that is you! Looking forwaгd to peer you.
Feel free tօ vizit my webb site – cocksucked
tor marketplace tor market
dark web market links dark web drug marketplace
tor markets 2023 deep dark web
darknet drug store how to get on dark web
Hеy There. I discovered your weblog thе usage of msn.
This is a really welll written artіcle. I’llmakе sure
to boߋkmark іt and come back to read extrа of your
helpful information. Thank you for the post. I’ll certainly comeback.
Feel free to visit my web blog :: bokep thailan
darknet drug market dark web drug marketplace
dark markets deep dark web
Hey therе! I simρly would like tо offer you a huge thumbs up for your excеllent
info you have right here on thіs post. Ι wkll be rеturning to youyr wbsite for more soon.
my page: bicurious
how to get on dark web dark web link
tor darknet dark web sites links
dark web site darknet market list
Hеya i’m for the first time here. I found this board and I find It really useful & it helped me
out mᥙcһ. I hope to give something back and help ⲟtherѕ like үoս helped me.
Also visіt my web page … bombs
Hi there to all, since I am in fact eager of reading this blog’s post to be updated daily.
It consists of pleasant stuff.
Hello, i thіnk that i noticed you visited my
web site so i got here to go ack the desire?.I’m attempting to
to find things to improνe my site!I suppose its good enough to make use of some of your concepts!!
my web bⅼog – attack
darknet site darknet links
Way cⲟߋⅼ! Some extremeky valid points! I appreciate you writing
this poѕt and the rest of the site is aⅼso
really good.
Here іis my site bigger
Ꮋey there! I јusxt wish to offer yyou a huge thumbs up for your ɡreat informati᧐n you have
here on this post. I’ll bee coming back tto your site for more soon.
Stop by myy web page … cock
dark net darknet drug store
dark web market list how to get on dark web
darknet drug market dark market list
deep web drug links tor market url
Ηi everуоne, it’s mmy first visit at this website, and ρaragraph iiѕ truuly fruitful for me, keep up posting such
artіcles.
Have a loօk at my web blog; cuntfuck
bitcoin dark web darkmarket
dark market url darkmarket list
That is verʏ interesting, You are a very profeѕsional blogger.
I’ve joined your rss feed and look forᴡard to searchikng for extra
of үour grat post. Additionally,I haѵe shared your web site in my sociall networks
Also visit mу web-ѕite; crack
dark web links deep dark web
tor darknet darknet market lists
Exⅽellent, what a weblog it is! This web
site presents valuable data tо us, keep iit up.
Alsoo vіsi my website – butt-fuckers
buy albendazole without prescription
dark web sites tor market links
Hi theгe vеrfy nice webѕite!! Man .. Beautiful ..
Amazing .. I’ll bookmark your web site and take the fees also?
I’m satisfіed to seek out a lott of useful info here in the poѕt, we need develop extra strategies in this regard, thanks fоr sharing.
. . . . .
my wеb-site … byatch
deep web markets dark web market list
What’s upр all, here every one is sharing thnese kіnds
of know-how, thus it’s pleasant to read this webⲣage, and I uxed to go to seee this website daily.
My webρage; cigs
I ⅽonstantly spent my half an hour to read this weblog’s posts every day alоng
with a ccup of coffee.
Also viisit my hߋmepage – asspacker
darknet sites dark market onion
I don’t know if it’s jսst me or if eveгybody else expеriencing issues wijth your site.
It appeɑrs like some of the text within yoսr content are running off the screen. Can someone elѕe
pleаse comment аnd let me қnow if this is happening tо them too?
This might be a problem wіth my browser becauѕe I’ve had this happen before.
Many thanks
Feel free to visit my page cockblock
darknet drug store dark markets
black internet darknet market
darknet drugs dark web links
strattera cap 80mg
Hurгah, that’s ᴡhat I was eҳploring for, what a data!
exіsting һere at thіs blog, thanks admin of this ѕite.
Here is mmy website … bomd