aspose file tools*
The moose likes JSP and the fly likes Custom Tags & Custom Types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom Tags & Custom Types" Watch "Custom Tags & Custom Types" New topic
Author

Custom Tags & Custom Types

Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
I have a type in menuitem.java (called, surprisingly enough, "menuitem") that extends Object. In a tag library, called mnuTab.java, I have:



In the jsp I have:



When executed, I get this error:

The method setMenuBar(menuitem[]) in the type mnuTag is not applicable for the arguments (Object)


I was just going to declare the setter method as passing in an Object, and then cast it to the menuitem[] type. This is marginal programming practice, I know, but I didn't know any other way around it, until I came across this thread in this forum:

http://www.coderanch.com/t/280242/JSP/java/taglib-parameters-other-types-than

(See? I'm looking first;-).

The last post in this thread indicates you can pass in custom types, but I can't get it to work, even after trying various casts in the jsp file. How does one do this and be typesafe?

TIA


-------<br />Thanks & regards,<br />anw
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

getAttribute returns an Object. You cannot get around casting.

P.S. It makes code surprisingly difficult to read when you don't follow normal conventions. Please consider following Java conventions on the naming of classes. E.g. MenuItem rather than menuitem.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Addemdum: switching to JSP 2.0 and the use of EL expressions will eliminate any need for casting.
Allen Williams
Ranch Hand

Joined: Sep 04, 2006
Posts: 136
Ha! That, I think, is the ultimate solution. Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom Tags & Custom Types