RE: Re[2]: Multiple input fields

2001-08-20 Thread Michael Terry

Kent -

Can you give an example of how you did this? I used an ArrayList
in my form, with one entry per select element in my form. This
works fine when only single options can be selected, but I can't
get it to work with 

In my JSP I want to generate a variable number of multiple select
boxes containing values taken from a Hashtable containing
ArrayLists of beans (one entry in the Hashtable for each box):

  <% int n = 0; %>
  
<%
  prop = "attList[" + n + "]";
  n++;
%>


  

  

In the associated form bean, I use an ArrayList named attList which will
contain the variable number of String[] arrays of selected values passed
back from my select boxes. So I have my getter and setter thus:

public String[] getAttList(int idx) {
return (String[])attList.get(idx);
}

public void setAttList(int idx, String[] keys) {
attList.set(idx, keys);
}

But the problem is that this collapses in BeanUtils.populate with a
type mismatch error:

  javax.servlet.ServletException: BeanUtils.populate
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:486)
  Root cause: 
  java.lang.IllegalArgumentException: argument type mismatch
at java.lang.reflect.Method.invoke(Native Method)
at 
org.apache.struts.util.PropertyUtils.setIndexedProperty(PropertyUtils.java:688)

There is no problem when I remove the multiple=true from the select element
and use the following:

public String getAttList(int idx) {
return (String)attList.get(idx);
}

public void setAttList(int idx, String key) {
attList.set(idx, key);
}

I've already posted this problem once, but answer came there none.

Michael

-Original Message-
From: Kent Roylance [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 17, 2001 2:50 AM
To: [EMAIL PROTECTED]; Anthony Xin Chen
Subject: RE: Re[2]: Multiple input fields


Actually, you can do one better than that.  Just pass in beans to the
form(can have collections in them), and that way you don't have to put a
bunch of attributes and getter/setters in your form.  Of course you will
need a getter for your bean that you put in your ActionForm.  As a result,
my ActionForms are very thin, take advantage of reuseability, better
performance, and alot less work.

Learned trial and error on this one,

Kent

-Original Message-
From: Anthony Xin Chen [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 16, 2001 6:48 PM
To: SUPRIYA MISRA
Subject: Re[2]: Multiple input fields


Hello there,

Although  I have not tried it personally, I read from the list that it
can  be  done  if  your  ActionForm  provides  a  setter which takes a
collection and a getter which returns a collection.


Thursday, August 16, 2001, 5:03:15 AM, you wrote:

SM> No the last category will overwrite the previous ones. You need to add
an
SM> integer to category.

SM> <%int x= 0 ;%>
SM> 
SM> <%x++;%>
SM>   " value="">

SM> request.getParameterValues("category0")
SM> request.getParameterValues("category1")

SM> The best option is to loop it the value of x times;


>>From: [EMAIL PROTECTED] (Andrew Myers)
>>Reply-To: [EMAIL PROTECTED]
>>To: [EMAIL PROTECTED]
>>Subject: Multiple input fields
>>Date: Thu, 16 Aug 2001 02:22:02 -0400
>>
>>Is it possible to have multiple input fields with the same name?
>>
>>Eg. In regular HTML I would do this
>>
>>
>>
>>
>> 
>>   Category
>>   Description
>> 
>>
>> 
>>   
>>   
>> 
>>
>> 
>>   
>>   
>> 
>>
>>...
>>
>>
>>
>>
>>
>>
>>Then when access all the parameters by calling
>>request.getParameterValues("category")
>>Can ActionForm Beans handle multiple values with the same field name?  If
>>so how is this achieved?
>>
>>Thanks,
>>Andrew.
>>
>>
>>__
>>Your favorite stores, helpful shopping tools and great gift ideas.
>>Experience the convenience of buying online with Shop@Netscape!
>>http://shopnow.netscape.com/
>>
>>Get your own FREE, personal Netscape Mail account today at
>>http://webmail.netscape.com/
>>


SM> _
SM> Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp



--
Best regards,
 Anthony





Indexed properties with multiple select options

2001-07-18 Thread Michael Terry

Hi -

In my JSP I'm generating (a small unknown number) of multiselect
SELECT drop-down lists with values taken from a Hashtable containing
ArrayLists, such that each drop-down corresponds to the strings in
an ArrayList in the Hashtable:

  <% int n = 0; %>
  
<%
  prop = "attributeKeys[" + n + "]";
  n++;
%>


  

  

In the associated form bean, I assume I need to use an ArrayList (named attList
below) which will contain the String[] arrays of selected values passed back
from my SELECTs. So I have my indexed property String[] attributeKeys with
getter and setter thus:

public String[] getAttList(int idx) {
return (String[])attList.get(idx);
}

public void setAttList(int idx, String[] keys) {
attList.set(idx, keys);
}

But the problem is that this collapses in BeanUtils.populate with a
type mismatch error:

  javax.servlet.ServletException: BeanUtils.populate
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:486)
  Root cause: 
  java.lang.IllegalArgumentException: argument type mismatch
at java.lang.reflect.Method.invoke(Native Method)
at 
org.apache.struts.util.PropertyUtils.setIndexedProperty(PropertyUtils.java:688)

I'm quite new to Struts, and can't understand what I'm doing wrong!
Is it actually possible to use multiple select options with indexed
properties? Any ideas? Thanks!

Michael