You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Marcello Savino <Ma...@aldebra.com> on 2007/04/04 14:35:21 UTC

Iterating over a List of JavaBean

Hi all,
In a jsp file i need to iterate over an ArrayList of javabean :

The bean:

public class myBean implements java.io.Serializable{
	private Integer code;
	private String name;
	
	public Integer getCode(){return code;}
	public String getName(){return name;}
	
	public void setCode(Integer val){ code=val;}
	public void setName(String val){ name=val;}
	
}

In the action class i set the form.list variable:
...
public ActionForward list(
	        ActionMapping mapping,
	        ActionForm form,
	        HttpServletRequest request,
	        HttpServletResponse response)
	        throws IOException, ServletException {
				try {
					myBean[] l;
					l=getMyBeanArray();
					((ActionFormBase)form).list=new
ArrayList();
					for (int i=0;i<l.length;i++){
	
((ActionFormBase)form).lista.add(l);	
					}
					request.setAttribute("lista",
((ActionFormBase)form).lista);
				} catch (Exception e){
	
((ActionFormBase)form).ErrMessage=e.getMessage() ;
				}
			return(mapping.getInputForward() );
}
...
And this is my jsp code:
...
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
...
<logic:iterate id="index" name="lista" type="myBean">
	<bean:write name="index" property="code"/>
	<bean:write name="index" property="name"/>
</logic:iterate>

But what i get is an Exception:
java.lang.ClassCastException: [LmyBean;

Any help will be greatly appreciated.
Thanks in advance

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


unsibscribe

Posted by Levan Dvalishvili <dv...@verticali.com>.
unsubscribe

-----Original Message-----
From: Marcello Savino [mailto:Marcello.Savino@aldebra.com] 
Sent: Wednesday, April 04, 2007 8:35 AM
To: Struts Users Mailing List
Subject: Iterating over a List of JavaBean

Hi all,
In a jsp file i need to iterate over an ArrayList of javabean :

The bean:

public class myBean implements java.io.Serializable{
	private Integer code;
	private String name;
	
	public Integer getCode(){return code;}
	public String getName(){return name;}
	
	public void setCode(Integer val){ code=val;}
	public void setName(String val){ name=val;}
	
}

In the action class i set the form.list variable:
...
public ActionForward list(
	        ActionMapping mapping,
	        ActionForm form,
	        HttpServletRequest request,
	        HttpServletResponse response)
	        throws IOException, ServletException {
				try {
					myBean[] l;
					l=getMyBeanArray();
					((ActionFormBase)form).list=new
ArrayList();
					for (int i=0;i<l.length;i++){
	
((ActionFormBase)form).lista.add(l);	
					}
					request.setAttribute("lista",
((ActionFormBase)form).lista);
				} catch (Exception e){
	
((ActionFormBase)form).ErrMessage=e.getMessage() ;
				}
			return(mapping.getInputForward() );
}
...
And this is my jsp code:
...
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
...
<logic:iterate id="index" name="lista" type="myBean">
	<bean:write name="index" property="code"/>
	<bean:write name="index" property="name"/>
</logic:iterate>

But what i get is an Exception:
java.lang.ClassCastException: [LmyBean;

Any help will be greatly appreciated.
Thanks in advance

---------------------------------------------------------------------
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


R: Iterating over a List of JavaBean

Posted by Marcello Savino <Ma...@aldebra.com>.
My sight is getting worst so fast  ! Sob !
Of course , now it works!
Thanks a lot to everybody !

Marcello Savino
ALDEBRA S.p.A. 
tel.  0461302441

-----Messaggio originale-----
Da: Antonio Petrelli [mailto:antonio.petrelli@gmail.com] 
Inviato: mercoledì 4 aprile 2007 14.43
A: Struts Users Mailing List
Oggetto: Re: Iterating over a List of JavaBean

2007/4/4, Marcello Savino <Ma...@aldebra.com>:
>                                         for (int i=0;i<l.length;i++){
>
> ((ActionFormBase)form).lista.add(l);
>                                         }

It seems like a bug, you are putting the array in the list a lot of times :-)

Antonio

---------------------------------------------------------------------
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


Re: Iterating over a List of JavaBean

Posted by Antonio Petrelli <an...@gmail.com>.
2007/4/4, Marcello Savino <Ma...@aldebra.com>:
>                                         for (int i=0;i<l.length;i++){
>
> ((ActionFormBase)form).lista.add(l);
>                                         }

It seems like a bug, you are putting the array in the list a lot of times :-)

Antonio

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


Re: Iterating over a List of JavaBean

Posted by Dave Newton <ne...@yahoo.com>.
--- Marcello Savino wrote:
> for (int i = 0; i < l.length; i++) {
>     ((ActionFormBase) form).lista.add(l);
> }

You may mean l[i] here.

Tip o' the day: cast your form once, early; it's much
easier to read.

d.



 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

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


RE: Iterating over a List of JavaBean

Posted by "Raghupathy, Gurumoorthy" <Gu...@nielsen.com>.
Remove the type="myBean" from your jsp and try 

Regards
Guru
 
------------------------------------------------------------------------
-----------
Gurumoorthy Raghupathy
Email  :  gurumoorthy.raghupathy@vnuinc.co.uk
Internal Extn : 2337 
External Phone  : 01483712337 
Nielsen Book
3rd Floor Midas House
62 Goldsworth Road
Woking Surrey GU21 6LQ
Visit us at  : http://www.nielsenbookdata.co.uk/ 
------------------------------------------------------------------------
-----------
-----Original Message-----
From: Marcello Savino [mailto:Marcello.Savino@aldebra.com] 
Sent: 04 April 2007 13:35
To: Struts Users Mailing List
Subject: Iterating over a List of JavaBean

Hi all,
In a jsp file i need to iterate over an ArrayList of javabean :

The bean:

public class myBean implements java.io.Serializable{
	private Integer code;
	private String name;
	
	public Integer getCode(){return code;}
	public String getName(){return name;}
	
	public void setCode(Integer val){ code=val;}
	public void setName(String val){ name=val;}
	
}

In the action class i set the form.list variable:
...
public ActionForward list(
	        ActionMapping mapping,
	        ActionForm form,
	        HttpServletRequest request,
	        HttpServletResponse response)
	        throws IOException, ServletException {
				try {
					myBean[] l;
					l=getMyBeanArray();
					((ActionFormBase)form).list=new
ArrayList();
					for (int i=0;i<l.length;i++){
	
((ActionFormBase)form).lista.add(l);	
					}
					request.setAttribute("lista",
((ActionFormBase)form).lista);
				} catch (Exception e){
	
((ActionFormBase)form).ErrMessage=e.getMessage() ;
				}
			return(mapping.getInputForward() );
}
...
And this is my jsp code:
...
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
...
<logic:iterate id="index" name="lista" type="myBean">
	<bean:write name="index" property="code"/>
	<bean:write name="index" property="name"/>
</logic:iterate>

But what i get is an Exception:
java.lang.ClassCastException: [LmyBean;

Any help will be greatly appreciated.
Thanks in advance

---------------------------------------------------------------------
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