Forums Register Login

Regarding attributes to custom tags

+Pie Number of slices to send: Send
I have a doubt in custom tags attribute values

Say I have like this in my jsp

....
<%
Dog d=new Dog();
d.setName("d1");
%>
<prefix1:tag1 dog=d>

can I not write like this.In HFSJ its mentioned that attribute values should be either Strings or expressions.Can anyone explain me why?
+Pie Number of slices to send: Send
You can use
<prefix1:tag1 dog="${d}">
or
<prefix1:tag1 dog='<%=(Dog)request.getAttribute("bean")%>'>

But you can not wirte
<prefix1:tag1 dog=d>
it will throw exception as quote symbol expected .
+Pie Number of slices to send: Send
You can use
<prefix1:tag1 dog="${d}">
or
<prefix1:tag1 dog='<%=(Dog)request.getAttribute("d")%>'>

But you can not wirte
<prefix1:tag1 dog=d>
it will throw exception as quote symbol expected .
+Pie Number of slices to send: Send
Renu,

If you are expecting a different answer (or) an extra piece of information then, here it is ...

If your attributes are primitives, then the string that we pass in the JSP file's custom tag, is auto-converted to the primitive.

However, if you want to set value of an attribute to an Object, an explicit setter method with proper parameter should be present in your tag handler and the syntax should be how 'gowher' mentioned in his explanation.
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 820 times.
Similar Threads
Remove variable from session in javascript
tags as other tags' attribute value
Passing ArrayList to JSP custom Tag?
custom tags for dynamic values inside JSTL tags
Using Custom tags inside HTML or Scriptlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:03:51.