You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by BISO <bi...@tantawi.net> on 2006/10/25 04:51:33 UTC

Re: javabeans with Collection (Set)

Thanks Laurie for your response. 
I used BeanUtils and It worked well with me  :) 

Unfortunately, convert(Class type, Object value) works only with single
Object not Object array. Do you know away to make it work with arrays. 
My goal to Convert String[] to a java.util.Set

Thanks again
BISO



Laurie Harper wrote:
> 
> That's because Struts doesn't know how to turn a set of HTML request 
> parameters into a Set of Something. There are a couple of options: you 
> could, perhaps, register a converter with BeanUtils what would do this 
> for you, at which point your existing code would probably work as you 
> were expecting; or you could change your form bean to expose the 
> 'values' field as an indexed property [1]. The latter is probably the 
> one you want.
> 
> L.
> 
> [1] http://struts.apache.org/1.2.9/userGuide/building_view.html#indexed
> 
> BISO wrote:
>> Dears,
>> I have a "User" bean with java.util.Set property.
>> I create a struts form with a list to select multiple values from and
>> then
>> store them in the set. 
>> I am getting this exception:
>> java.lang.IllegalArgumentException: Cannot invoke
>> com.myapp.struts.User.setValues - argument type mismatch
>> 
>> ---
>> public class User extends org.apache.struts.action.ActionForm {
>>     
>>     private String name;
>>     private Set values;
>> 
>>     public String getName() {
>>         return name;
>>     }
>> 
>>     public void setName( String name) {
>>         this.name = name;
>>     }
>> 
>>     public Set getValues() {
>>         return values;
>>     }
>> 
>>     public void setValues(Set values) {
>>         this.values = values;
>>     } 
>> }
>> ----
>> 
>> <html:form action="/post">
>>     <html:text property="name"/>
>>     
>>     <html:select property="values" multiple="true">
>>         <html:option value="1"/>
>>         <html:option value="2"/>
>>         <html:option value="3"/>
>>         <html:option value="4"/>
>>         <html:option value="5"/>
>>         
>>       <html:submit />
>>     </html:select>
>> </html:form>
>> 
>> 
>> ------
>> 
>> Thanks in advance
>> 
>> BISO
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/javabeans-with-Collection-%28Set%29-tf2491548.html#a6985310
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: javabeans with Collection (Set)

Posted by Martin Gainty <mg...@hotmail.com>.
Biso-

have u looked at implementing with StringArrayConverter.convert ?
try
{
StringArrayConverter.convert(Class classType,Object valueToBeConvertedToclassType);
}
catch(ConversionException excp)
{
}
javadoc at
http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/converters/StringArrayConverter.html

M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "BISO" <bi...@tantawi.net>
To: <us...@struts.apache.org>
Sent: Sunday, October 29, 2006 6:54 PM
Subject: Re: javabeans with Collection (Set)


> 
> Dear Laurie,
> 
> Thanks alot for your support.
> my registration code:
> ConvertUtils.register(new SetConverter(),Set.class);
> 
> BISO
> 
> 
> Laurie Harper wrote:
>> 
>> I haven't tried it, but I'd assume you would have to register a 
>> converter for String[], rather than just String. What does your 
>> converter registration code look like?
>> 
>> L.
>> 
>> BISO wrote:
>>> Thanks Laurie for your response. 
>>> I used BeanUtils and It worked well with me  :) 
>>> 
>>> Unfortunately, convert(Class type, Object value) works only with single
>>> Object not Object array. Do you know away to make it work with arrays. 
>>> My goal to Convert String[] to a java.util.Set
>>> 
>>> Thanks again
>>> BISO
>>> 
>>> 
>>> 
>>> Laurie Harper wrote:
>>>> That's because Struts doesn't know how to turn a set of HTML request 
>>>> parameters into a Set of Something. There are a couple of options: you 
>>>> could, perhaps, register a converter with BeanUtils what would do this 
>>>> for you, at which point your existing code would probably work as you 
>>>> were expecting; or you could change your form bean to expose the 
>>>> 'values' field as an indexed property [1]. The latter is probably the 
>>>> one you want.
>>>>
>>>> L.
>>>>
>>>> [1] http://struts.apache.org/1.2.9/userGuide/building_view.html#indexed
>>>>
>>>> BISO wrote:
>>>>> Dears,
>>>>> I have a "User" bean with java.util.Set property.
>>>>> I create a struts form with a list to select multiple values from and
>>>>> then
>>>>> store them in the set. 
>>>>> I am getting this exception:
>>>>> java.lang.IllegalArgumentException: Cannot invoke
>>>>> com.myapp.struts.User.setValues - argument type mismatch
>>>>>
>>>>> ---
>>>>> public class User extends org.apache.struts.action.ActionForm {
>>>>>     
>>>>>     private String name;
>>>>>     private Set values;
>>>>>
>>>>>     public String getName() {
>>>>>         return name;
>>>>>     }
>>>>>
>>>>>     public void setName( String name) {
>>>>>         this.name = name;
>>>>>     }
>>>>>
>>>>>     public Set getValues() {
>>>>>         return values;
>>>>>     }
>>>>>
>>>>>     public void setValues(Set values) {
>>>>>         this.values = values;
>>>>>     } 
>>>>> }
>>>>> ----
>>>>>
>>>>> <html:form action="/post">
>>>>>     <html:text property="name"/>
>>>>>     
>>>>>     <html:select property="values" multiple="true">
>>>>>         <html:option value="1"/>
>>>>>         <html:option value="2"/>
>>>>>         <html:option value="3"/>
>>>>>         <html:option value="4"/>
>>>>>         <html:option value="5"/>
>>>>>         
>>>>>       <html:submit />
>>>>>     </html:select>
>>>>> </html:form>
>>>>>
>>>>>
>>>>> ------
>>>>>
>>>>> Thanks in advance
>>>>>
>>>>> BISO
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context: http://www.nabble.com/javabeans-with-Collection-%28Set%29-tf2491548.html#a7067154
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

Re: javabeans with Collection (Set)

Posted by BISO <bi...@tantawi.net>.
Dear Laurie,

Thanks alot for your support.
my registration code:
ConvertUtils.register(new SetConverter(),Set.class);

BISO


Laurie Harper wrote:
> 
> I haven't tried it, but I'd assume you would have to register a 
> converter for String[], rather than just String. What does your 
> converter registration code look like?
> 
> L.
> 
> BISO wrote:
>> Thanks Laurie for your response. 
>> I used BeanUtils and It worked well with me  :) 
>> 
>> Unfortunately, convert(Class type, Object value) works only with single
>> Object not Object array. Do you know away to make it work with arrays. 
>> My goal to Convert String[] to a java.util.Set
>> 
>> Thanks again
>> BISO
>> 
>> 
>> 
>> Laurie Harper wrote:
>>> That's because Struts doesn't know how to turn a set of HTML request 
>>> parameters into a Set of Something. There are a couple of options: you 
>>> could, perhaps, register a converter with BeanUtils what would do this 
>>> for you, at which point your existing code would probably work as you 
>>> were expecting; or you could change your form bean to expose the 
>>> 'values' field as an indexed property [1]. The latter is probably the 
>>> one you want.
>>>
>>> L.
>>>
>>> [1] http://struts.apache.org/1.2.9/userGuide/building_view.html#indexed
>>>
>>> BISO wrote:
>>>> Dears,
>>>> I have a "User" bean with java.util.Set property.
>>>> I create a struts form with a list to select multiple values from and
>>>> then
>>>> store them in the set. 
>>>> I am getting this exception:
>>>> java.lang.IllegalArgumentException: Cannot invoke
>>>> com.myapp.struts.User.setValues - argument type mismatch
>>>>
>>>> ---
>>>> public class User extends org.apache.struts.action.ActionForm {
>>>>     
>>>>     private String name;
>>>>     private Set values;
>>>>
>>>>     public String getName() {
>>>>         return name;
>>>>     }
>>>>
>>>>     public void setName( String name) {
>>>>         this.name = name;
>>>>     }
>>>>
>>>>     public Set getValues() {
>>>>         return values;
>>>>     }
>>>>
>>>>     public void setValues(Set values) {
>>>>         this.values = values;
>>>>     } 
>>>> }
>>>> ----
>>>>
>>>> <html:form action="/post">
>>>>     <html:text property="name"/>
>>>>     
>>>>     <html:select property="values" multiple="true">
>>>>         <html:option value="1"/>
>>>>         <html:option value="2"/>
>>>>         <html:option value="3"/>
>>>>         <html:option value="4"/>
>>>>         <html:option value="5"/>
>>>>         
>>>>       <html:submit />
>>>>     </html:select>
>>>> </html:form>
>>>>
>>>>
>>>> ------
>>>>
>>>> Thanks in advance
>>>>
>>>> BISO
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/javabeans-with-Collection-%28Set%29-tf2491548.html#a7067154
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: javabeans with Collection (Set)

Posted by Laurie Harper <la...@holoweb.net>.
I haven't tried it, but I'd assume you would have to register a 
converter for String[], rather than just String. What does your 
converter registration code look like?

L.

BISO wrote:
> Thanks Laurie for your response. 
> I used BeanUtils and It worked well with me  :) 
> 
> Unfortunately, convert(Class type, Object value) works only with single
> Object not Object array. Do you know away to make it work with arrays. 
> My goal to Convert String[] to a java.util.Set
> 
> Thanks again
> BISO
> 
> 
> 
> Laurie Harper wrote:
>> That's because Struts doesn't know how to turn a set of HTML request 
>> parameters into a Set of Something. There are a couple of options: you 
>> could, perhaps, register a converter with BeanUtils what would do this 
>> for you, at which point your existing code would probably work as you 
>> were expecting; or you could change your form bean to expose the 
>> 'values' field as an indexed property [1]. The latter is probably the 
>> one you want.
>>
>> L.
>>
>> [1] http://struts.apache.org/1.2.9/userGuide/building_view.html#indexed
>>
>> BISO wrote:
>>> Dears,
>>> I have a "User" bean with java.util.Set property.
>>> I create a struts form with a list to select multiple values from and
>>> then
>>> store them in the set. 
>>> I am getting this exception:
>>> java.lang.IllegalArgumentException: Cannot invoke
>>> com.myapp.struts.User.setValues - argument type mismatch
>>>
>>> ---
>>> public class User extends org.apache.struts.action.ActionForm {
>>>     
>>>     private String name;
>>>     private Set values;
>>>
>>>     public String getName() {
>>>         return name;
>>>     }
>>>
>>>     public void setName( String name) {
>>>         this.name = name;
>>>     }
>>>
>>>     public Set getValues() {
>>>         return values;
>>>     }
>>>
>>>     public void setValues(Set values) {
>>>         this.values = values;
>>>     } 
>>> }
>>> ----
>>>
>>> <html:form action="/post">
>>>     <html:text property="name"/>
>>>     
>>>     <html:select property="values" multiple="true">
>>>         <html:option value="1"/>
>>>         <html:option value="2"/>
>>>         <html:option value="3"/>
>>>         <html:option value="4"/>
>>>         <html:option value="5"/>
>>>         
>>>       <html:submit />
>>>     </html:select>
>>> </html:form>
>>>
>>>
>>> ------
>>>
>>> Thanks in advance
>>>
>>> BISO
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
> 


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