struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Cantatore <strutsuser...@yahoo.com>
Subject java.lang.ClassCastException trying to populate html:select
Date Wed, 02 Jul 2003 22:22:08 GMT
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


Mime
View raw message