You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Sayre <ri...@gmail.com> on 2009/05/11 15:40:40 UTC

Converter trying to set String on int field

I have a bunch of check boxes called userId. In my action I have int
userId[] and setUserId(int[] ids)

When I select a checkbox the conversion works normally.  When I dont
check any boxes on the form and submit, I get the following:

2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
for property userId. Mapping size: 4
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
converter for property [userId] = none found
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
converter for property [userId] = none found
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
default type converter
[com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
for property userId. Mapping size: 4
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
converter for property [userId] = none found
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
converter for property [userId] = none found
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
default type converter
[com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Error setting value
ognl.MethodFailedException: Method "setUserId" failed for object
com.abc.UsersAction@1db2215 [java.lang.NoSuchMethodException:
setUserId(java.lang.String)]

For some reason when no ids are selected it is trying to set the value
as a String.

1) Is this normal behavior?
2) Is there a way to work around it?

Thank you,

Rich

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


Re: Converter trying to set String on int field

Posted by Richard Sayre <ri...@gmail.com>.
After some debugging the culprit was the checkbox interceptor.

It uses false as a default value when nothing is selected.  I tried
setting the uncheckedValue to -1 and it didnt work.

<interceptor-ref name="completeDefault">
               <param name="checkbox.uncheckedValue">-1</param>
 </interceptor-ref>

I upgraded to the latest version of Struts 2 and then it worked.

On Mon, May 11, 2009 at 3:01 PM, Richard Sayre <ri...@gmail.com> wrote:
> It is also happening in a Date field I have.  If no dates are entered
> in the text box then I get the same error.  If I provide a date then
> the conversion works.
>
> I am currently moving through the XWork and OGNL source to see what is
> causing this.
>
>
> On Mon, May 11, 2009 at 1:48 PM,  <mu...@aol.com> wrote:
>>
>>  I bet it has something to do with a null not being assignable to an int.
>> Chris
>>
>>
>>
>>
>>
>>
>>
>> -----Original Message-----
>> From: Richard Sayre <ri...@gmail.com>
>> To: Struts Users Mailing List <us...@struts.apache.org>
>> Sent: Mon, 11 May 2009 11:44 am
>> Subject: Re: Converter trying to set String on int field
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> After some further investigation I found that any array type that has
>> no values from the form on submit will call setXXX(String).
>>
>> I checked the source of
>> com.opensymphony.xwork2.util.XWorkBasicConverter and this is the first
>> thing it does:
>>
>> if (value == null || toType.isAssignableFrom(value.getClass())) {
>>            // no need to convert at all, right?
>>            return value;
>>        }
>>
>> So I'm still unclear as to why setXXX(String) is called.  I even used
>> a custom converter, and I am getting the same results.  When I return
>> null from my converter setXXX(String) is called.
>>
>> If anyone has any suggestions on how to handle this it would be
>> greatly appreciated
>>
>> Thanks
>> Rich
>>
>>
>> On Mon, May 11, 2009 at 11:10 AM, Richard Sayre <ri...@gmail.com> wrote:
>>> I have a bunch of check boxes called userId. In my action I have int
>>> userId[] and setUserId(int[] ids)
>>>
>>> When I select a checkbox the conversion works normally. ?When I dont
>>> check any boxes on the form and submit, I get the following:
>>>
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
>>> for property userId. Mapping size: 4
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
>>> converter for property [userId] = none found
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
>>> converter for property [userId] = none found
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
>>> default type converter
>>> [com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
>>> for property userId. Mapping size: 4
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
>>> converter for property [userId] = none found
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
>>> converter for property [userId] = none found
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
>>> default type converter
>>> [com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
>>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Error setting value
>>> ognl.MethodFailedException: Method "setUserId" failed for object
>>> com.abc.UsersAction@1db2215 [java.lang.NoSuchMethodException:
>>> setUserId(java.lang.String)]
>>>
>>> For some reason when no ids are selected it is trying to set the value
>>> as a String.
>>>
>>> 1) Is this normal behavior?
>>> 2) Is there a way to work around it?
>>>
>>> Thank you,
>>>
>>> Rich
>>>
>>
>> ---------------------------------------------------------------------
>> 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


Re: Converter trying to set String on int field

Posted by Richard Sayre <ri...@gmail.com>.
It is also happening in a Date field I have.  If no dates are entered
in the text box then I get the same error.  If I provide a date then
the conversion works.

I am currently moving through the XWork and OGNL source to see what is
causing this.


On Mon, May 11, 2009 at 1:48 PM,  <mu...@aol.com> wrote:
>
>  I bet it has something to do with a null not being assignable to an int.
> Chris
>
>
>
>
>
>
>
> -----Original Message-----
> From: Richard Sayre <ri...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Mon, 11 May 2009 11:44 am
> Subject: Re: Converter trying to set String on int field
>
>
>
>
>
>
>
>
>
>
> After some further investigation I found that any array type that has
> no values from the form on submit will call setXXX(String).
>
> I checked the source of
> com.opensymphony.xwork2.util.XWorkBasicConverter and this is the first
> thing it does:
>
> if (value == null || toType.isAssignableFrom(value.getClass())) {
>            // no need to convert at all, right?
>            return value;
>        }
>
> So I'm still unclear as to why setXXX(String) is called.  I even used
> a custom converter, and I am getting the same results.  When I return
> null from my converter setXXX(String) is called.
>
> If anyone has any suggestions on how to handle this it would be
> greatly appreciated
>
> Thanks
> Rich
>
>
> On Mon, May 11, 2009 at 11:10 AM, Richard Sayre <ri...@gmail.com> wrote:
>> I have a bunch of check boxes called userId. In my action I have int
>> userId[] and setUserId(int[] ids)
>>
>> When I select a checkbox the conversion works normally. ?When I dont
>> check any boxes on the form and submit, I get the following:
>>
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
>> for property userId. Mapping size: 4
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
>> converter for property [userId] = none found
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
>> converter for property [userId] = none found
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
>> default type converter
>> [com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
>> for property userId. Mapping size: 4
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
>> converter for property [userId] = none found
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
>> converter for property [userId] = none found
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
>> default type converter
>> [com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
>> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Error setting value
>> ognl.MethodFailedException: Method "setUserId" failed for object
>> com.abc.UsersAction@1db2215 [java.lang.NoSuchMethodException:
>> setUserId(java.lang.String)]
>>
>> For some reason when no ids are selected it is trying to set the value
>> as a String.
>>
>> 1) Is this normal behavior?
>> 2) Is there a way to work around it?
>>
>> Thank you,
>>
>> Rich
>>
>
> ---------------------------------------------------------------------
> 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


Re: Converter trying to set String on int field

Posted by mu...@aol.com.
 I bet it has something to do with a null not being assignable to an int.
Chris


 


 

-----Original Message-----
From: Richard Sayre <ri...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Mon, 11 May 2009 11:44 am
Subject: Re: Converter trying to set String on int field










After some further investigation I found that any array type that has
no values from the form on submit will call setXXX(String).

I checked the source of
com.opensymphony.xwork2.util.XWorkBasicConverter and this is the first
thing it does:

if (value == null || toType.isAssignableFrom(value.getClass())) {
            // no need to convert at all, right?
            return value;
        }

So I'm still unclear as to why setXXX(String) is called.  I even used
a custom converter, and I am getting the same results.  When I return
null from my converter setXXX(String) is called.

If anyone has any suggestions on how to handle this it would be
greatly appreciated

Thanks
Rich


On Mon, May 11, 2009 at 11:10 AM, Richard Sayre <ri...@gmail.com> wrote:
> I have a bunch of check boxes called userId. In my action I have int
> userId[] and setUserId(int[] ids)
>
> When I select a checkbox the conversion works normally. ?When I dont
> check any boxes on the form and submit, I get the following:
>
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
> for property userId. Mapping size: 4
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
> converter for property [userId] = none found
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
> converter for property [userId] = none found
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
> default type converter
> [com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
> for property userId. Mapping size: 4
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
> converter for property [userId] = none found
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
> converter for property [userId] = none found
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
> default type converter
> [com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Error setting value
> ognl.MethodFailedException: Method "setUserId" failed for object
> com.abc.UsersAction@1db2215 [java.lang.NoSuchMethodException:
> setUserId(java.lang.String)]
>
> For some reason when no ids are selected it is trying to set the value
> as a String.
>
> 1) Is this normal behavior?
> 2) Is there a way to work around it?
>
> Thank you,
>
> Rich
>

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



 


Re: Converter trying to set String on int field

Posted by Richard Sayre <ri...@gmail.com>.
After some further investigation I found that any array type that has
no values from the form on submit will call setXXX(String).

I checked the source of
com.opensymphony.xwork2.util.XWorkBasicConverter and this is the first
thing it does:

if (value == null || toType.isAssignableFrom(value.getClass())) {
            // no need to convert at all, right?
            return value;
        }

So I'm still unclear as to why setXXX(String) is called.  I even used
a custom converter, and I am getting the same results.  When I return
null from my converter setXXX(String) is called.

If anyone has any suggestions on how to handle this it would be
greatly appreciated

Thanks
Rich


On Mon, May 11, 2009 at 11:10 AM, Richard Sayre <ri...@gmail.com> wrote:
> I have a bunch of check boxes called userId. In my action I have int
> userId[] and setUserId(int[] ids)
>
> When I select a checkbox the conversion works normally.  When I dont
> check any boxes on the form and submit, I get the following:
>
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
> for property userId. Mapping size: 4
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
> converter for property [userId] = none found
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
> converter for property [userId] = none found
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
> default type converter
> [com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Property: userId
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Class: com.abc.UsersAction
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - converter is null
> for property userId. Mapping size: 4
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - field-level type
> converter for property [userId] = none found
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - global-level type
> converter for property [userId] = none found
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - falling back to
> default type converter
> [com.opensymphony.xwork2.util.XWorkBasicConverter@82fba9]
> 2009-05-11 10:54:28,606 [http-8080-6] DEBUG []: - Error setting value
> ognl.MethodFailedException: Method "setUserId" failed for object
> com.abc.UsersAction@1db2215 [java.lang.NoSuchMethodException:
> setUserId(java.lang.String)]
>
> For some reason when no ids are selected it is trying to set the value
> as a String.
>
> 1) Is this normal behavior?
> 2) Is there a way to work around it?
>
> Thank you,
>
> Rich
>

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