aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Regarding attributes to custom tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Regarding attributes to custom tags" Watch "Regarding attributes to custom tags" New topic
Author

Regarding attributes to custom tags

Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
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

Joined: Feb 07, 2005
Posts: 643
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

Joined: Feb 07, 2005
Posts: 643
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

Joined: Sep 15, 2004
Posts: 230
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.


Regards,<br />Mani<br />SCJP 1.4 (95%)<br />SCWCD 1.4 (94%)
 
wood burning stoves
 
subject: Regarding attributes to custom tags