• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding attributes to custom tags

 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic