You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ding Lei <di...@ipanel.cn> on 2004/05/22 07:44:54 UTC

How to get length of an array(collection)

Hello all,
	There is an array(dsmccList) obtained by a self-defined tag, and I wanna to send the length of the array
	as an hidden property, as following:
	<iPanel:appListData id='dsmccList'/>
	<c:set var="dataCount" value="${dsmccList.length}"/>

	But this causes exception:
javax.servlet.jsp.el.ELException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.

	Any ideas? Thanks!


-- 
Yours,

   <<<:::::   D i n g    L e i   ::::::>>
 ||                                      ||
 || Ext: 8106                            ||
 || Email: <dinglei [A] ipanel [O] cn>   ||
 || Dept. Of Technology/Engineering      ||
 || Embedded Information Services Inc.   ||
 ||                                      ||
<((((((    =====================     )))))>>>
	
"Good-bye.  I am leaving because I am bored."
		-- George Saunders' dying words

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to get length of an array(collection)

Posted by Henrique VIECILI <vi...@softplan.com.br>.
Hi Ding!

You can try this:

<bean:size id="collectionLength" name="dsmccList" />

You may look into struts-bean API documentation to understand how this tag works.

[]´s
Henrique Andrade Viecili
  ----- Original Message ----- 
  From: Ding Lei 
  To: user@struts.apache.org 
  Sent: Saturday, May 22, 2004 2:44 AM
  Subject: How to get length of an array(collection)


  Hello all,
  There is an array(dsmccList) obtained by a self-defined tag, and I wanna to send the length of the array
  as an hidden property, as following:
  <iPanel:appListData id='dsmccList'/>
  <c:set var="dataCount" value="${dsmccList.length}"/>

  But this causes exception:
  javax.servlet.jsp.el.ELException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.

  Any ideas? Thanks!


  -- 
  Yours,

     <<<:::::   D i n g    L e i   ::::::>>
   ||                                      ||
   || Ext: 8106                            ||
   || Email: <dinglei [A] ipanel [O] cn>   ||
   || Dept. Of Technology/Engineering      ||
   || Embedded Information Services Inc.   ||
   ||                                      ||
  <((((((    =====================     )))))>>>

  "Good-bye.  I am leaving because I am bored."
  -- George Saunders' dying words

  ---------------------------------------------------------------------
  To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
  For additional commands, e-mail: user-help@struts.apache.org

Re: How to get length of an array(collection)

Posted by Ding Lei <di...@ipanel.cn>.
Joe, Henrique & Robert:
   Thank you for replies, they all works :)

yours,
lei   

On Mon, May 24, 2004 at 03:38:54PM -0500, Joe Germuska wrote:
> At 1:44 PM +0800 5/22/04, Ding Lei wrote:
> >Hello all,
> >	There is an array(dsmccList) obtained by a self-defined tag, 
> >and I wanna to send the length of the array
> >	as an hidden property, as following:
> >	<iPanel:appListData id='dsmccList'/>
> >	<c:set var="dataCount" value="${dsmccList.length}"/>
> >
> >	But this causes exception:
> >javax.servlet.jsp.el.ELException: The "." operator was supplied with 
> >an index value of type "java.lang.String" to be applied to a List or 
> >array, but that value cannot be converted to an integer.
> 
> In JSTL 1.1 (JSP 2.0), you can use the 'length' function:
> http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fn/length.fn.html
> 
> Short of that, no, there is no convenient way to do what you suggest 
> without writing scriptlets.  The JSTL Expression language expects the 
> value to the right of a "." operator to be a bean property name, and 
> neither arrays nor collections have methods that conform to bean 
> property naming conventions that help you do this.
> 
> Actually, rather than writing scriptlets, I usually define a second 
> request-scoped variable that holds the length, or wrap the list in a 
> bean of my own that translates between "getLength()" and array.length 
> or collection.size()
> 
> Maybe you can adjust your custom tag to define two variables, the 
> list and another with the length of the list.
> 
> Joe
> 
> -- 
> Joe Germuska            
> Joe@Germuska.com  
> http://blog.germuska.com    
>       "Imagine if every Thursday your shoes exploded if you tied them 
> the usual way.  This happens to us all the time with computers, and 
> nobody thinks of complaining."
>             -- Jef Raskin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

-- 
Yours,

   <<<:::::   D i n g    L e i   ::::::>>
 ||                                      ||
 || Ext: 8106                            ||
 || Email: <dinglei [A] ipanel [O] cn>   ||
 || Dept. Of Technology/Engineering      ||
 || Embedded Information Services Inc.   ||
 ||                                      ||
<((((((    =====================     )))))>>>
	
A child of five could understand this!  Fetch me a child of five.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to get length of an array(collection)

Posted by Ding Lei <di...@ipanel.cn>.
Joe, Henrique & Robert:
   Thank you for replies, they all works :)

yours,
lei   

On Mon, May 24, 2004 at 03:38:54PM -0500, Joe Germuska wrote:
> At 1:44 PM +0800 5/22/04, Ding Lei wrote:
> >Hello all,
> >	There is an array(dsmccList) obtained by a self-defined tag, 
> >and I wanna to send the length of the array
> >	as an hidden property, as following:
> >	<iPanel:appListData id='dsmccList'/>
> >	<c:set var="dataCount" value="${dsmccList.length}"/>
> >
> >	But this causes exception:
> >javax.servlet.jsp.el.ELException: The "." operator was supplied with 
> >an index value of type "java.lang.String" to be applied to a List or 
> >array, but that value cannot be converted to an integer.
> 
> In JSTL 1.1 (JSP 2.0), you can use the 'length' function:
> http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fn/length.fn.html
> 
> Short of that, no, there is no convenient way to do what you suggest 
> without writing scriptlets.  The JSTL Expression language expects the 
> value to the right of a "." operator to be a bean property name, and 
> neither arrays nor collections have methods that conform to bean 
> property naming conventions that help you do this.
> 
> Actually, rather than writing scriptlets, I usually define a second 
> request-scoped variable that holds the length, or wrap the list in a 
> bean of my own that translates between "getLength()" and array.length 
> or collection.size()
> 
> Maybe you can adjust your custom tag to define two variables, the 
> list and another with the length of the list.
> 
> Joe
> 
> -- 
> Joe Germuska            
> Joe@Germuska.com  
> http://blog.germuska.com    
>       "Imagine if every Thursday your shoes exploded if you tied them 
> the usual way.  This happens to us all the time with computers, and 
> nobody thinks of complaining."
>             -- Jef Raskin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

-- 
Yours,

   <<<:::::   D i n g    L e i   ::::::>>
 ||                                      ||
 || Ext: 8106                            ||
 || Email: <dinglei [A] ipanel [O] cn>   ||
 || Dept. Of Technology/Engineering      ||
 || Embedded Information Services Inc.   ||
 ||                                      ||
<((((((    =====================     )))))>>>
	
A child of five could understand this!  Fetch me a child of five.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to get length of an array(collection)

Posted by Ding Lei <di...@ipanel.cn>.
Joe, Henrique & Robert:
   Thank you for replies, they all works :)

yours,
lei   

On Mon, May 24, 2004 at 03:38:54PM -0500, Joe Germuska wrote:
> At 1:44 PM +0800 5/22/04, Ding Lei wrote:
> >Hello all,
> >	There is an array(dsmccList) obtained by a self-defined tag, 
> >and I wanna to send the length of the array
> >	as an hidden property, as following:
> >	<iPanel:appListData id='dsmccList'/>
> >	<c:set var="dataCount" value="${dsmccList.length}"/>
> >
> >	But this causes exception:
> >javax.servlet.jsp.el.ELException: The "." operator was supplied with 
> >an index value of type "java.lang.String" to be applied to a List or 
> >array, but that value cannot be converted to an integer.
> 
> In JSTL 1.1 (JSP 2.0), you can use the 'length' function:
> http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fn/length.fn.html
> 
> Short of that, no, there is no convenient way to do what you suggest 
> without writing scriptlets.  The JSTL Expression language expects the 
> value to the right of a "." operator to be a bean property name, and 
> neither arrays nor collections have methods that conform to bean 
> property naming conventions that help you do this.
> 
> Actually, rather than writing scriptlets, I usually define a second 
> request-scoped variable that holds the length, or wrap the list in a 
> bean of my own that translates between "getLength()" and array.length 
> or collection.size()
> 
> Maybe you can adjust your custom tag to define two variables, the 
> list and another with the length of the list.
> 
> Joe
> 
> -- 
> Joe Germuska            
> Joe@Germuska.com  
> http://blog.germuska.com    
>       "Imagine if every Thursday your shoes exploded if you tied them 
> the usual way.  This happens to us all the time with computers, and 
> nobody thinks of complaining."
>             -- Jef Raskin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

-- 
Yours,

   <<<:::::   D i n g    L e i   ::::::>>
 ||                                      ||
 || Ext: 8106                            ||
 || Email: <dinglei [A] ipanel [O] cn>   ||
 || Dept. Of Technology/Engineering      ||
 || Embedded Information Services Inc.   ||
 ||                                      ||
<((((((    =====================     )))))>>>
	
A child of five could understand this!  Fetch me a child of five.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to get length of an array(collection)

Posted by Joe Germuska <Jo...@Germuska.com>.
At 1:44 PM +0800 5/22/04, Ding Lei wrote:
>Hello all,
>	There is an array(dsmccList) obtained by a self-defined tag, 
>and I wanna to send the length of the array
>	as an hidden property, as following:
>	<iPanel:appListData id='dsmccList'/>
>	<c:set var="dataCount" value="${dsmccList.length}"/>
>
>	But this causes exception:
>javax.servlet.jsp.el.ELException: The "." operator was supplied with 
>an index value of type "java.lang.String" to be applied to a List or 
>array, but that value cannot be converted to an integer.

In JSTL 1.1 (JSP 2.0), you can use the 'length' function:
http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fn/length.fn.html

Short of that, no, there is no convenient way to do what you suggest 
without writing scriptlets.  The JSTL Expression language expects the 
value to the right of a "." operator to be a bean property name, and 
neither arrays nor collections have methods that conform to bean 
property naming conventions that help you do this.

Actually, rather than writing scriptlets, I usually define a second 
request-scoped variable that holds the length, or wrap the list in a 
bean of my own that translates between "getLength()" and array.length 
or collection.size()

Maybe you can adjust your custom tag to define two variables, the 
list and another with the length of the list.

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
       "Imagine if every Thursday your shoes exploded if you tied them 
the usual way.  This happens to us all the time with computers, and 
nobody thinks of complaining."
             -- Jef Raskin

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: How to get length of an array(collection)

Posted by Robert Taylor <rt...@mulework.com>.
<c:set var="dataCount" value="${fn:length(dsmccList)}"/>

robert

> -----Original Message-----
> From: Ding Lei [mailto:dinglei@ipanel.cn]
> Sent: Saturday, May 22, 2004 1:45 AM
> To: user@struts.apache.org
> Subject: How to get length of an array(collection)
> 
> 
> Hello all,
> 	There is an array(dsmccList) obtained by a self-defined tag, and I wanna to send the length of the array
> 	as an hidden property, as following:
> 	<iPanel:appListData id='dsmccList'/>
> 	<c:set var="dataCount" value="${dsmccList.length}"/>
> 
> 	But this causes exception:
> javax.servlet.jsp.el.ELException: The "." operator was supplied with an index value of type "java.lang.String" to be 
> applied to a List or array, but that value cannot be converted to an integer.
> 
> 	Any ideas? Thanks!
> 
> 
> -- 
> Yours,
> 
>    <<<:::::   D i n g    L e i   ::::::>>
>  ||                                      ||
>  || Ext: 8106                            ||
>  || Email: <dinglei [A] ipanel [O] cn>   ||
>  || Dept. Of Technology/Engineering      ||
>  || Embedded Information Services Inc.   ||
>  ||                                      ||
> <((((((    =====================     )))))>>>
> 	
> "Good-bye.  I am leaving because I am bored."
> 		-- George Saunders' dying words
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org