File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes setters and getters for field in customTag question 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 » Java » JSP
Bookmark "setters and getters for field in customTag question" Watch "setters and getters for field in customTag question" New topic
Author

setters and getters for field in customTag question

Denis Yuzvyk
Greenhorn

Joined: Dec 06, 2004
Posts: 22
Hi , i have question :
My custom tag has field
private Locale locale;
//and getters ,setters for it
public Locale getlocale(){return locale;}
public void setlocale(Locale l ) { locale = l;}

tdl:
<attribute>
<name>locale</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
in jsp page i have:
<prefix:tag locale="ua/UA" > body </prefix:tag>
I wont that that tag create locale with given string ....
but for thes i need setter with such signature :
public void setLocale (String loc){ locale = new Locale(loc);}
but with such signature Tamcat says:
Unable to find setter method for attribute: locale

//another example


foe example ,if i have field:
private int number;
//so why with this setter in tomcat work ok
setNumber(int i){
munber = i;
}
//and with this setter is error :
//cannot find setter for field : number
setNumber(String str){
number= Integer.parseInt(str);
}


how to deal with this ?


Thx.
M. Gagnon
Ranch Hand

Joined: Feb 18, 2004
Posts: 68
It looks like the parameter type in the setter method and the type for the corresponding data member have to be the same (or perhaps compatible types in an inheritance hierarchy). From an example in ProJSP by Apress (excellent JSP book, by the way):

"... the instance variable and the setter method are defined to take Collection rather than String, and at request time the setter method will be called with a Collection of ... objects." The author hasn't stated explicitly that the rule is to match type, but he's kind of implying that. And yes, you can pass an object other than type String. I've done it.

How about:

<yourLib:yourTag yourAttr="<%= new Locale(yourString) %>" />
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setters and getters for field in customTag question