• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Tags & Custom Types

 
Allen Williams
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Addemdum: switching to JSP 2.0 and the use of EL expressions will eliminate any need for casting.
 
Allen Williams
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ha! That, I think, is the ultimate solution. Thanks!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic