• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Runtime type substitution on logic:iterate

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using struts 1.1 and I want to have a multipurpose jsp. I am getting the ClassCastException when I try to do something similar to the following:
<% String dynamicType = "com.myorg.myClass"; %>
<logic:iterate name="TableActionForm" property="genericVos" id="tablelist" indexId="indexNum" type="<%=dynamicType%>">
The string evaluates properly elsewhere on the page and copying the value into the iterate tag (so it is not dynamically generated) works fine - it is the correct class and the iterate works properly.
The struts-logic.tld says that the type property has a rtexprvalue=true. The plan was to pass in the type of the class as a Tiles attribute but I can't even get the above to work. Has anyone done something like this, is there another way to do this?
Thanks,
Scott
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Scott. We have a forum devoted to Struts, so I'm moving your topic along to there.
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have your classes implement an Interface and use type="MyInterface"
 
Scott Bailey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ray Stojonic:
have your classes implement an Interface and use type="MyInterface"


I thought about that (and very good suggestion, thanks) but I need to call an extra getter method on some of the classes that not all the classes have (I would be using logic:match tags to check a value passed from a tiles definition to decide whether include the call to the getter.)
I suppose I could add that extra method to the base class but to complicate things all these classes are value objects generated by a utility directly from database tables and views and I have a delivery Monday so I was hoping to come up with a JSP solution (other than cut and paste!). Thanks again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic