Re: Casting beans in JSP
On Fri, 20 Apr 2001, John Raley wrote: Try using bean:define and specifying the type you want. The 'id' attribute value in bean:define will be the downcast reference. Example: % ... a bean of type Foo is in the page under the attribute name 'aFoo' % bean:define name='aFoo' type='mypkg.SubFoo' id='aSubFoo'/ aSubFoo now refers to aFoo through a reference of type SubFoo. This works as advertised, but I should point out that if you are only using Struts tags (or jsp:getProperty to access the properties of the actual bean, casting is not strictly necessary. Craig
Casting beans in JSP
heya folx, is there anyway to use a tag to cast an object from one type to another? just curious. the reason is that a top level bean implements a generic interface and i need to access the 'actual' object rather than a the generic attributes returned by interface. i'm loathe to use any java in my JSPs, so i'm looking for some other sort of solution. i'm going to look for a solution on the server side, but i think it's a fairly normal design pattern. thoughts? ideas? chris
Re: Casting beans in JSP
I don't know if one already exists, but if not... You could write your own that would take pageContext attribute id (scripting variable name) of the object to cast the type to cast it to. (fully qualified of coarse) pageContext attribute id (scripting variable name) of the new object Something like: CAST id="myGenericObject" type="myComp.ActualClass" castid="myActualClass"/ There would be very little code involved. Take a look at the DefineTag in Struts. It has an example of making an object available as a scripting variable. HTH, Pete Chris Butler wrote: heya folx, is there anyway to use a tag to cast an object from one type to another? just curious. the reason is that a top level bean implements a generic interface and i need to access the 'actual' object rather than a the generic attributes returned by interface. i'm loathe to use any java in my JSPs, so i'm looking for some other sort of solution. i'm going to look for a solution on the server side, but i think it's a fairly normal design pattern. thoughts? ideas? chris begin:vcard n:; x-mozilla-html:FALSE org:BRIMG SRC="http://www.irista.com/logo/irista.gif"BRBRFONT Color=#80FONT SIZE=2BBringing Vision to Your Supply Chain adr:;; version:2.1 end:vcard
Re: Casting beans in JSP
Try using bean:define and specifying the type you want. The 'id' attribute value in bean:define will be the downcast reference. Example: % ... a bean of type Foo is in the page under the attribute name 'aFoo' % bean:define name='aFoo' type='mypkg.SubFoo' id='aSubFoo'/ aSubFoo now refers to aFoo through a reference of type SubFoo. Chris Butler wrote: heya folx, is there anyway to use a tag to cast an object from one type to another? just curious. the reason is that a top level bean implements a generic interface and i need to access the 'actual' object rather than a the generic attributes returned by interface. i'm loathe to use any java in my JSPs, so i'm looking for some other sort of solution. i'm going to look for a solution on the server side, but i think it's a fairly normal design pattern. thoughts? ideas? chris