struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Iterate
Date Wed, 28 Mar 2001 02:46:28 GMT


On Tue, 27 Mar 2001, raghu tadi wrote:

> How would the bean element holding a vector of String objects be type casted 
> to a String Object.
> Snippet :
> 
> <%
> 	Vector v = new Vector();
> 	v.addElement(new String("John Doe"));
> 	v.addElement(new String("Jane Doe"));
> 	pageContext.setAttribute("v",v, PageContext.PAGE_SCOPE);
> %>
> <logic:iterate id="main" name="v">
> // Snippet gives the general picture as of what im looking for..
> <% String name = (String)(<bean:write name="main"/>) %>
> out.println(name);
> </logic:iterate>
> 

You cannot use custom tags inside a scriptlet, so the above solution won't
work.

> Its imperative that i get the bean element into a String since this String 
> object would be passed into a SQL Query or a method returning a Query 
> result. This would look Stupid but definitely serves the purpose..
> Please Respond.
> 
> Raghu..
> 

How about something like this (although Struts isn't really designed to
make scriptlets work well, it does cooperate with them :-):

<%
  Vector names = new Vector();
  names.addElement("John Doe");
  names.addElement("Jane Doe");
  pageContext.setAttribute("names", names, PageContext.PAGE_SCOPE);
%>

<logic:iterate id="name" name="names" type="java.lang.String">
  The current name is <%= name %>.
</logic:iterate>

The "type" attribute on the <logic:iterate> tag determines the Java type
of the scripting variable that is created (name).  By default, it is
java.lang.Object.

Craig


Mime
View raw message