struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sandeep Takhar <sandeep_tak...@yahoo.com>
Subject Re: java.lang.ClassCastException trying to populate html:select
Date Thu, 03 Jul 2003 21:02:50 GMT
I think the reason why no one has tackled this is
because there is a lot of things this could be.

The exact error isn't mentioned either. Maybe show a
bit of the stack trace?  

Let me take a crack at it by giving you the basics of
what struts does and then maybe this will help?

I wouldn't use a ValueInfoBean that extends ActionForm
- there is no need.  There is an
org.apache.struts.util.LabelValueBean that does
exactly this and is used by some of the tags:
optionsCollection for example.

Your struts-config should have a 
/register in the path and should declare what your
form is and what scope it is in.

The line where you create the arrayForm is unnecessary
since it will be created for you by the time the
execute is called.

I would use optionsCollection with LabelValue Beans
instead of using collection attribute with options
tag.  Read the user docs carefully since the select
and multiple select is the hardest one.

sandeep




--- Alex Cantatore <strutsuser949@yahoo.com> wrote:
> Please?  Can anyone help me?  I'm really lost here.
> 
> -Alex
> --- Alex Cantatore <strutsuser949@yahoo.com> wrote:
> > Hi all, I have been working on this for two days
> and
> > it's gotten to the point where I cannot see what I
> > did
> > wrong in the least.  I'm just trying to figure out
> > how
> > to make it work; the actual program is a bare
> shell
> > with the sole purpose of populating a
> <html:select>.
> > 
> > There is a RegisterAction,success.jsp, ArrayForm,
> > and
> > ValueInfoBean.
> > 
> > You start by calling register.do, which creates an
> > ArrayList and puts three ValueInfoBeans in it.  It
> > then sets ArrayForm to carry the ArrayList,
> wherein
> > it
> > is converted to a Collection.  Control is then
> > passed
> > to success.jsp which tries to read in the
> Collection
> > to populate the <html:select>, but instead gives
> me
> > a
> > ClassCastException.  Any help would be greatly
> > appreciated.  Code follows.
> > 
> > public class ValueInfoBean extends ActionForm {
> > 
> > 	private String value = null;
> > 	private String info = null;
> > 
> > 	public String getValue() {
> > 		return value;
> > 	}
> > 
> > 	public void setValue(String v) {
> > 		value = v;
> > 	}
> > 
> > 	public String getInfo() {
> > 		return info;
> > 	}
> > 
> > 	public void setInfo(String i) {
> > 		info = i;
> > 	}
> > 
> > 	public ValueInfoBean() {
> > 
> > 		super();
> > 
> > 	}
> > 	public void reset(ActionMapping mapping,
> > HttpServletRequest request) {
> > 		value = null;
> > 		info = null;
> > 	}
> > }
> > 
> > public class ArrayForm extends ActionForm {
> > 
> > 	private Collection theArray = null;
> > 
> > 	public Collection getTheArray() {
> > 		return theArray;
> > 	}
> > 
> > 	public void setTheArray(ArrayList t) {
> > 		theArray = t;
> > 	}
> > 
> > 	public ArrayForm() {
> > 
> > 		super();
> > 
> > 	}
> > 	
> > 	public void reset(ActionMapping mapping,
> > HttpServletRequest request) {
> > 
> > 		theArray = null;
> > 
> > 	}
> > }
> > 
> > public class RegisterAction extends Action {
> > 
> > 	/**
> > 	* Constructor
> > 	*/
> > 	public RegisterAction() {
> > 
> > 		super();
> > 
> > 	}
> > 	
> > 	public ActionForward perform(
> > 		ActionMapping mapping,
> > 		ActionForm form,
> > 		HttpServletRequest request,
> > 		HttpServletResponse response)
> > 		throws IOException, ServletException {
> > 
> > 		ActionErrors errors = new ActionErrors();	
> > 
> > 		ArrayList myList = new ArrayList();
> > 		
> > 		ValueInfoBean myBean = new ValueInfoBean();
> > 				
> > 		for(int i = 0; i < 3; i++)
> > 		{
> > 			myBean.setValue(String.valueOf(i));
> > 			myBean.setInfo(i + "Please work" + i);
> > 			myList.add(myBean);
> > 		}
> > 		
> > 		
> > 		ArrayForm thisArray = new ArrayForm();
> > 		thisArray.setTheArray(myList);	
> > 		
> > 		request.setAttribute("beanArray", thisArray);
> > 
> > 
> > 		return mapping.findForward("success");
> > 	}
> > }
> > 
> > and success.jsp:
> > 
> > <html:form action="register.do">
> > <bean:define id="theArray" scope="request"
> > name="beanArray" type="java.util.Collection"/>
> > 
> > <html:select property="username" multiple="true">
> >  <html:options collection="theArray"
> > property="value"
> > labelProperty="info"/>
> > </html:select>
> > 
> > </html:form>
> > </BODY>
> > </html:html>
> > 
> > Once again, major thanks to anyone who can help in
> > the
> > least.
> > 
> > -Alex
> > 
> > __________________________________
> > Do you Yahoo!?
> > SBC Yahoo! DSL - Now only $29.95 per month!
> > http://sbc.yahoo.com
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > struts-user-help@jakarta.apache.org
> > 
> 
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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


Mime
View raw message