Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Struts and checkboxes

Status
Not open for further replies.

ahsin

Programmer
Oct 1, 2003
8
US
Hi All,
I am using struts to develop a mail application. I have send mail page, where the user can select the addersses from a set of checkboxes.

<html:checkbox property=&quot;toAddress&quot; value=&quot;CFO&quot;/>CFO
</div>
<div style=&quot;position:absolute;top=630px;left=10px&quot;>
Sales&quot;/>VP-Sales -->
<html:checkbox property=&quot;toAddress&quot; value=&quot;VP-Sales&quot;/>VP-Sales
</div>
<div style=&quot;position:absolute;top=630px;left=100px&quot;>
value=&quot;COO&quot;/>COO-->
<html:checkbox property=&quot;toAddress&quot; value=&quot;COO&quot;/>COO
</div>
In the form bean i try to access the checkboxes as:
private String[] toAddress;
public String[] getToAddress(){

return toAddress;
}
public void setToAddress(String[] _toAddress){

toAddress = _toAddress;
}


Now, when i submit the form i get the error:

javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.IllegalArgumentException: argument type mismatch
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1789)
org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1684)
org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1713)
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1019)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


Is it wrong to access the checkboxes of the same name as an array? Cant struts recognise it?
Please help...i need help soon.............

Ahsin


 
What data type do you have for the toAddress property in the form bean. Check box should map to string array (String[]).
 
Thanks byam,
I am using String[] to retrieve it. Anyways i got my problem solved. The error does not come now. I dont know what exactly caused it to disappear. The only change i made was, to change all checkboxes as:
<html:checkbox name=&quot;toAddress&quot;/> . I used name instaed of property and it worked.

Bye
Ahsin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top