Avatar billede fredand Forsker
15. maj 2007 - 17:37 Der er 6 kommentarer og
1 løsning

Is there a better solution then this inside a JSP?

Hello!

We maintain a pretty big system that "out of the box" come with many jsp-pages.

Often we need to go in and modify them.
My last task is to do a filtering on a Map before it gets printed out.

Origianlly it looks like:

<%
Some code
Map map = fillFromDatabase();
%>
html bla bla html
<%
Some code that render the Map
%>

We wouldlike to minimize new code in these jsp-pages.
A easy solution for me is just to create a class and add a row like below:

<%
Some code
Map map = fillFromDatabase();
map = com.a.FilterManager.filter(map);
%>
html bla bla html
<%
Some code that render the Map
%>

But is there a better way to do modifications to a jsp-page then the example above.

Best regards
Fredrik
Avatar billede arne_v Ekspert
15. maj 2007 - 18:18 #1
I think best practice would be to:

* instantiate an object based on config info to get the data
* change that config info to loade a filtering wrapper with the same interface
  as the original database class

This could be done using Spring bean factory and a "before advice".

But other implementations are possible.
Avatar billede fredand Forsker
15. maj 2007 - 20:14 #2
Thanks Arne!
1) But would you say that my solution is bad?
2) Btw to you have any online example or tutorial that explains or show your solution. It really sounds great!

Btw please give a svar so I can reward you mate.
Best regards
Fredrik
Avatar billede arne_v Ekspert
15. maj 2007 - 22:52 #3
Avatar billede arne_v Ekspert
15. maj 2007 - 22:56 #4
I don't think I have an example of how to wrap a call - only before and after advice.

And contrary to what I wrote earlier then you should not use before advice, but
instead use around advice.
Avatar billede arne_v Ekspert
15. maj 2007 - 22:57 #5
Answer.

And I can quickly produce an example with around advice if you need it.
Avatar billede arne_v Ekspert
26. november 2007 - 21:56 #6
closing time ?
Avatar billede fredand Forsker
27. november 2007 - 10:05 #7
Thanks alot Arne!
Best regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester