You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Cantatore <st...@yahoo.com> on 2003/07/03 00:22:08 UTC
java.lang.ClassCastException trying to populate html:select
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
RE: java.lang.ClassCastException trying to populate html:select
Posted by Steve Raeburn <st...@ninsky.com>.
FYI Each web application has its own struts.jar so different web apps could
be running different struts versions.
If you need to use LabelValueBean in an earlier version, you can always copy
the source. Don't ya just love open source?
Steve
> -----Original Message-----
> From: Alex Cantatore [mailto:strutsuser949@yahoo.com]
> Sent: July 3, 2003 2:21 PM
> To: Struts Users Mailing List
> Subject: Re: java.lang.ClassCastException trying to populate html:select
>
>
> I forgot to mention it, but I can't use
> org.apache.struts.util.LabelValueBean, unfortunately,
> as I am using an older version of Struts. Though it
> would be nice to upgrade, my supervisor has told me
> that I have to use the older version as the server is
> set up to run it and there are other apps on the
> server that require it.
...
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: java.lang.ClassCastException trying to populate html:select
Posted by Alex Cantatore <st...@yahoo.com>.
I forgot to mention it, but I can't use
org.apache.struts.util.LabelValueBean, unfortunately,
as I am using an older version of Struts. Though it
would be nice to upgrade, my supervisor has told me
that I have to use the older version as the server is
set up to run it and there are other apps on the
server that require it. Or something. It was one of
those, "Because I said so," situations, so there's
really nothing I can do with respect to that.
I'm fooling around with some of the other things you
mentioned, but I've never heard of optionsCollection
before now. I think it is 1.1 as well though, yes?
I'm stuck with 1.0.2 solutions.
The complete error message follows, my apologies for
not including it originally.
-Alex
[Servlet Error]-[JSP 1.2 Processor]:
java.lang.ClassCastException:
com.ejgallo.chapteroneweb.app.ArrayForm
at
org.apache.jsp._success._jspService(_success.java:132)
at
com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
at
com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:598)
at
com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:696)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at
com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at
com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:258)
at
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:872)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:491)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:173)
at
org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at
com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at
com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:258)
at
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:872)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:491)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:173)
at
com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at
com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:199)
at
com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at
com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at
com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
at
com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at
com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
at
com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
at
com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)
--- Sandeep Takhar <sa...@yahoo.com> wrote:
> 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 <st...@yahoo.com> wrote:
> > Please? Can anyone help me? I'm really lost
> here.
> >
> > -Alex
> > --- Alex Cantatore <st...@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.
> > >
>
=== message truncated ===
__________________________________
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
Re: java.lang.ClassCastException trying to populate html:select
Posted by Sandeep Takhar <sa...@yahoo.com>.
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 <st...@yahoo.com> wrote:
> Please? Can anyone help me? I'm really lost here.
>
> -Alex
> --- Alex Cantatore <st...@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
Re: java.lang.ClassCastException trying to populate html:select
Posted by Alex Cantatore <st...@yahoo.com>.
Please? Can anyone help me? I'm really lost here.
-Alex
--- Alex Cantatore <st...@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