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 store darkweb marketplace
Every single Massachusetts on line sprts betting website, aapp and
retail sportsbbook has guidelines.
Feeel free too visit my page; 해외토토사이트
A handicap bet on them at -7, for that reason, is a bet which pays out if they win by eight poits or far more.
Check out my webpage :: 해외토토사이트
Youu are leaving AARP.org and going to the web site
of our trusted provider.
Review my website – 유흥알바
dark web market list tor dark web
how to access dark web how to get on dark web
darknet drugs tor markets links
Except for cryptocurrencies, all ppayment methods come with a transaction charge.
Feel free to visiit my homepage 해외토토사이트
All thee lenders on our list can supply you wiith your loan amounts within a couple of daays oof your initial application.
Heere is my blog post – 기타 대출
His parents did not approve they believed hhe ought to
be studying as an alternative.
Check out my web site :: 요정 알바
They hwve a lot of possible, so a llot mopre could bbe added in the future.
Also visit my web site :: https://161cb.com/
dark web websites dark market link
Interest is larger than nearby banks but begins low at 5.99% and goes up to 35.99% only with specific lenders.
My site :: 정부지원대출
This is a limited series, a spinoff of the madly common Shonda Rhimes Bridgerton series baxed
on Juia Quinn’s Regency romance book series.
Also visit my web-site; site
When you need emergency cash, you quickly fall into a
cycle of worry and desperation.
Here is my blkog 정부지원대출
darknet markets 2023 darknet links
You may think off an administrative assistant as somebody who sits
at a desk all day, answers phones, and varieties letters.
Feel free to surf to my site; website
Meanwhile, some aare demanding that thhe government tighten restrictions temporarily to manage the spread but at
the similar time to refrain from unclear, ambiguous, and
ineffective measures.
Here is my webpaage :: 쩜오 알바
Tickets for the weekly draws are ordinarily low-cost and can expense as tiny
as ₹2.
Also visit my website :: 파워볼중계
dark web drug marketplace darkmarket 2023
darknet markets 2023 tor darknet
lasix cheap online
25 mg atarax
dark web site dark web drug marketplace
buy generic adalat online order fexofenadine 120mg online generic fexofenadine 120mg
dark markets 2023 dark web sites
deep web sites deep dark web
That can leave borrowers open to predatory interest rawtes that may perhaps climb nicely into the hundreds.
Also visit my web site 대환대출
darknet websites darknet market list
bitcoin dark web dark web sites links
If you want reliability and a corporation wth a trusted reputation, this is
the one particular.
Feel free to surf to my webpage: 대환대출
how to access dark web deep web drug links
how to access dark web dark web access
dark market list darkmarket 2023
tor market url dark market link
atarax medicine
darkmarket 2023 tor markets 2023
dark markets tor markets
strattera 5mg
tor markets links darkweb marketplace
In India, employee moonlighting has gained attention, and the prime businesses are opinionating on it.
my site :: 밤알바
The Project has about 2,000 firms committed tto help women get back too work–
including Google, Apple, Meta and Accenture.
Look ihto my website; 이지알바
dark market url darknet market lists
deep web drug store darkweb marketplace
dark web markets dark web access
deep web links tor markets
dark market onion free dark web
dark web markets tor markets 2023
dark website dark web market links
darkmarket list tor marketplace