You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sundaram Ramasamy <su...@percipia.com> on 2001/04/20 15:07:45 UTC

getting bean properity in the scriptlet varible

Hi

I have collection, I was able to print the message like this.

<logic:iterate id="link" name="links" >
   <bean:write name="link" property="linkName" />	  
    
  </logic:iterate>

Is it possible to store the bean value into scriptlet varible.

<logic:iterate id="link" name="links" >
<%

	String name = link.getLinkName();

%>    
  </logic:iterate>

I tried this, its giving me following error.

Method getLinkName()  not found in class java.lan.object.

Any idea, how to get this value.

Thanks
Sundaram


Re: getting bean properity in the scriptlet varible

Posted by Peter Alfors <pe...@irista.com>.
I think that you want to use the "define" taglib.

Pete

Sundaram Ramasamy wrote:

> Hi
>
> I have collection, I was able to print the message like this.
>
> <logic:iterate id="link" name="links" >
>    <bean:write name="link" property="linkName" />
>
>   </logic:iterate>
>
> Is it possible to store the bean value into scriptlet varible.
>
> <logic:iterate id="link" name="links" >
> <%
>
>         String name = link.getLinkName();
>
> %>
>   </logic:iterate>
>
> I tried this, its giving me following error.
>
> Method getLinkName()  not found in class java.lan.object.
>
> Any idea, how to get this value.
>
> Thanks
> Sundaram

Re: getting bean properity in the scriptlet varible

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 20 Apr 2001, Sundaram Ramasamy wrote:

> Hi
> 
> I have collection, I was able to print the message like this.
> 
> <logic:iterate id="link" name="links" >
>    <bean:write name="link" property="linkName" />	  
>     
>   </logic:iterate>
> 
> Is it possible to store the bean value into scriptlet varible.
> 
> <logic:iterate id="link" name="links" >
> <%
> 
> 	String name = link.getLinkName();
> 
> %>    
>   </logic:iterate>
> 

The type of object created by the iterate tag is determined by the
"type" attribute.  If you don't include one, it creates a
java.lang.Object.

If the clas of a "link" object is com.mycompany.MyLink, you could say:

  <logic:iterate id="link" name="links" type="com.mycompany.MyLink">

Craig


Re: Casting beans in JSP

Posted by "Craig R. McClanahan" <cr...@apache.org>.

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


Re: Casting beans in JSP

Posted by John Raley <jo...@moonlight.com>.
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


Re: Casting beans in JSP

Posted by Peter Alfors <pe...@irista.com>.
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

Casting beans in JSP

Posted by Chris Butler <pa...@orpheusdesign.com>.
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