Thanks,Maurizio,

This is not a wrong approach.
but can be take a improved for easier use. :P

Regards.


On Tue, Nov 23, 2010 at 12:10 PM, Maurizio Cucchiara
<maurizio.cucchi...@gmail.com> wrote:
> Hi Knight,
> I take your point, JSONPopulator.convertPrimitive function maybe uses a
> wrong approach.
> Does anyone know why convert method process is driven by value and type
> instead of target type only?
>
> 2010/11/23 Knight Chen <dolt131...@gmail.com>
>
>> Hi All,
>> Thanks for reply, and sorry for my poor English.
>>
>> In this case:
>>
>> I have a POJO:
>> public class UserDTO {
>>      private int age;
>>      ...
>>      public void setAge(int age) {
>>            this.age = age;
>>      }
>> }
>>
>>
>> And Action has a property with this type:
>>
>> public Class UserAction {
>>      private UserDTO userInfo;
>>
>>      ...
>>      public void setUserInfo(UserDTO userInfo {
>>            this.userInfo = userInfo;
>>      }
>>
>>      ...
>> }
>>
>> when I use ajax request and JSON format to transfer this UserDTO obj,
>> this UserDTO is Serialization from html page's text input field, and
>> age input field is empty(user not enter and business logic allow
>> this),
>> then this JSON String will be like this:
>> {'userInfo' : { 'age' : ''}}
>>
>> so, when use JSON plugin to parse this JSON string to UserAction's
>> userInfo property,there will be a Number format exception ( for input
>> String "")
>>
>> I check JSONPopulator.java , it has process null value for int(or
>> other number primitive type) with default value 0,
>> I think if it can parse the "" to int/Integer(or other number type)
>> with 0/null like the same process above mentioned,
>> if do this will easier the front process, because front JS code will
>> not to check the age's type,and transform the empty text input value
>> "" to null.
>>
>> Just a suggeset.
>>
>> Thanks all.
>>
>> Regards,
>>
>> On Tue, Nov 23, 2010 at 9:46 AM, Maurizio Cucchiara
>> <maurizio.cucchi...@gmail.com> wrote:
>> > I'm not sure understand what you mean, it could be ognl conversion
>> related.
>> > For further details, could you provide the NPE stack?
>> >
>> > 2010/11/22 Knight Chen <dolt131...@gmail.com>
>> >
>> >> Hi all,
>> >>
>> >> I often encounter Number format exception when I use JSON plugin to
>> >> parse input String "" from AJAX request to Number,
>> >> because in Web front,  that will be a zero length String "" transfer
>> >> to backend if the text input has no enter,
>> >> so will encounter the Number format exception for input String "".
>> >>
>> >> I check the JSONPopulator, that has process the null value to 0 when
>> >> parse to Number type, but not process the String "",
>> >> So can JSONPopulator to support process String "" to null or 0,that
>> >> will be easier web front develop.
>> >>
>> >>
>> >> --
>> >> ========================
>> >> Knight Chen
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> >> For additional commands, e-mail: user-h...@struts.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > Maurizio Cucchiara
>> >
>>
>>
>>
>> --
>> ========================
>> Knight Chen
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
>
>
> --
> Maurizio Cucchiara
>



-- 
========================
Knight Chen

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

Reply via email to