Avatar billede fredand Forsker
13. december 2012 - 13:43 Der er 3 kommentarer

How to create custom tag taht supports %{

Hello!

(I'm from sweden so I write in english, but feel free to answer in danish)

Using struts-tags you can pass parameters within %{} like:
<img src="<s:url action='ImageAction?imageId=%{product.id}' />" />

But how do you do that with a custom  tag of your own?

I tried:
<my_custom_tags:OrderCounterTag productId="%{product.id}" title="Orders for "/>

But it do not work.

Do I need to put some extra support in my tag or is this impossible?

Best regards
Fredrik
Avatar billede fredand Forsker
13. december 2012 - 14:22 #1
Hello!

I found out that:

"EL support
has to be coded into your tag handler, it's not magically provided by
default unfortunately. Either use standard jsp <%= someValue %> to provide
the value, or add in EL support."

at:
http://bytes.com/topic/java/answers/17677-jsp-tld-question-why-my-custom-tag-isnt-picking-up-param-product-parameter

I will look into it.

How ever I looks like struts uses %{} and custom tags use ${}, correct me if I'm wrong.

It would be great if I could get hold of the same objects that struts manage from ${}.

I will look into EL and see what I find.

Best regards
Fredrik
Avatar billede fredand Forsker
13. december 2012 - 15:04 #2
Hello!

In my case the queryString to this page got the param I was looking for.
Then I could do it like:
<albinoni:OrderCounterTag productId="${productid}" title="Orders for "/>

How ever
1) I think it would be nice if I could use %{product.id} instead.
2) Oops it doesn't work in Chrome or Firefox, strange this should only be server side?

Best regards
Fredrik
Avatar billede arne_v Ekspert
14. december 2012 - 05:04 #3
Hvis du er paa JSP >= 2.0, saa skal EL expandes inden din tag handler kaldes.

Hvis du er paa JSP 1.x, saa skal du selv expande EL.
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