You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Илья Нарыжный <ph...@ydn.ru> on 2011/11/16 10:00:36 UTC

StringValue.toOptionalLong incorrect behavior

Hello,

I have page mounted as @MountPath("/page/#{pageId}")

Also I have following code:

public ViewPagePage(PageParameters params)
    {
        this(getEntityPkFor(params, Page.class, 1)); //1 - is default ID if
PK in url was not found
    }

and:

protected static Long getEntityPkFor(PageParameters params, Class clazz,
Long defaultPk)
    {
        String pkFieldName = EntitiesDescriptor.get().getPkFieldName(clazz);
        Long ret=null;
        if(pkFieldName!=null)
        {
            ret = params.get(pkFieldName).toOptionalLong();
        }
        if(ret==null)
        {
            ret = params.get("id").toOptionalLong();
        }
        return ret==null?defaultPk:ret;
    }

But(!!!) if ID was not put to the URL I have following Exception:

Caused by: org.apache.wicket.util.string.StringValueConversionException:
Unable
to convert '' to a Long value
        at
org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
va:589)
        at
org.apache.wicket.util.string.StringValue.toOptionalLong(StringValue.
java:657)
        at ru.ydn.wicket.EntityPage.getEntityPkFor(EntityPage.java:57)
        at ru.ydn.wicket.web.ViewPagePage.<init>(ViewPagePage.java:84)
        ... 37 more
Caused by: java.lang.NumberFormatException: For input string: ""
        at
java.lang.NumberFormatException.forInputString(NumberFormatException.
java:48)
        at java.lang.Long.parseLong(Long.java:431)
        at java.lang.Long.<init>(Long.java:678)
        at
org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
va:585)

The problem in following code:

public final Long toOptionalLong() throws StringValueConversionException
    {
        return (text == null) ? null : toLongObject();
    }

text should be checked for emptiness - not only null

What do you think?

Thanks,

Ilia

Re: StringValue.toOptionalLong incorrect behavior

Posted by Илья Нарыжный <ph...@ydn.ru>.
OK:)
Please find it here:
https://issues.apache.org/jira/browse/WICKET-4309

Thank you!
Regards,
Ilia

2011/12/20 Martin Grigorov <mg...@apache.org>

> Ticket please!
>
> 2011/12/20 Илья Нарыжный <ph...@ydn.ru>:
> > Hello,
> >
> > Up this topic. Are you planning to fix this functionality with
> > toOptionalString?
> >
> > Thanks,
> >
> > Ilis
> >
> > 2011/11/16 vineet semwal <vi...@gmail.com>
> >
> >>  yeah not needed for toOptionalString() but why not for
> >> toOptionalBoolean()?
> >>
> >> On Wed, Nov 16, 2011 at 3:39 PM, Martin Grigorov <mg...@apache.org>
> >> wrote:
> >> > Hi,
> >> >
> >> > On Wed, Nov 16, 2011 at 11:50 AM, vineet semwal
> >> > <vi...@gmail.com> wrote:
> >> >> martin i too think tooptionalMethods in StringValue should behave the
> >> >> way llia is saying ie. they should return null if text is empty or
> >> >> null..
> >> >
> >> > Hm. Not quite convinced.
> >> > ?a=b&c=&e=f is a valid query string and 'c' has value "" while 'g' has
> >> null
> >> >
> >> > maybe just some of toOptionalXyz() methods should use
> Strings.isEmpty()
> >> > e.g. toOptionalString() and toOptionalBoolean() should not check for
> ""
> >> >
> >> >> for eg. currently  public final Long toOptionalLong() throws
> >> >> StringValueConversionException
> >> >>        {
> >> >>                return (text == null) ? null : toLongObject();
> >> >>        }
> >> >>
> >> >> can be changed to
> >> >>  public final Long toOptionalLong() throws
> >> StringValueConversionException
> >> >>        {
> >> >>                return (Strings.isEmpty(text)) ? null :
> toLongObject();
> >> >>        }
> >> >>
> >> >> On Wed, Nov 16, 2011 at 2:57 PM, Martin Grigorov <
> mgrigorov@apache.org>
> >> wrote:
> >> >>> Hi,
> >> >>>
> >> >>> At least this is what the javadoc says:
> >> >>> "Convert to object types, returning null if text is null."
> >> >>>
> >> >>> I think the more appropriate method for you is
> >> >>> org.apache.wicket.util.string.StringValue.toLong(long) but it also
> >> >>> throws exceptions if the provided value is empty string.
> >> >>>
> >> >>> On Wed, Nov 16, 2011 at 11:00 AM, Илья Нарыжный <ph...@ydn.ru>
> >> wrote:
> >> >>>> Hello,
> >> >>>>
> >> >>>> I have page mounted as @MountPath("/page/#{pageId}")
> >> >>>>
> >> >>>> Also I have following code:
> >> >>>>
> >> >>>> public ViewPagePage(PageParameters params)
> >> >>>>    {
> >> >>>>        this(getEntityPkFor(params, Page.class, 1)); //1 - is
> default
> >> ID if
> >> >>>> PK in url was not found
> >> >>>>    }
> >> >>>>
> >> >>>> and:
> >> >>>>
> >> >>>> protected static Long getEntityPkFor(PageParameters params, Class
> >> clazz,
> >> >>>> Long defaultPk)
> >> >>>>    {
> >> >>>>        String pkFieldName =
> >> EntitiesDescriptor.get().getPkFieldName(clazz);
> >> >>>>        Long ret=null;
> >> >>>>        if(pkFieldName!=null)
> >> >>>>        {
> >> >>>>            ret = params.get(pkFieldName).toOptionalLong();
> >> >>>>        }
> >> >>>>        if(ret==null)
> >> >>>>        {
> >> >>>>            ret = params.get("id").toOptionalLong();
> >> >>>>        }
> >> >>>>        return ret==null?defaultPk:ret;
> >> >>>>    }
> >> >>>>
> >> >>>> But(!!!) if ID was not put to the URL I have following Exception:
> >> >>>>
> >> >>>> Caused by:
> >> org.apache.wicket.util.string.StringValueConversionException:
> >> >>>> Unable
> >> >>>> to convert '' to a Long value
> >> >>>>        at
> >> >>>>
> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
> >> >>>> va:589)
> >> >>>>        at
> >> >>>>
> org.apache.wicket.util.string.StringValue.toOptionalLong(StringValue.
> >> >>>> java:657)
> >> >>>>        at
> ru.ydn.wicket.EntityPage.getEntityPkFor(EntityPage.java:57)
> >> >>>>        at
> ru.ydn.wicket.web.ViewPagePage.<init>(ViewPagePage.java:84)
> >> >>>>        ... 37 more
> >> >>>> Caused by: java.lang.NumberFormatException: For input string: ""
> >> >>>>        at
> >> >>>>
> java.lang.NumberFormatException.forInputString(NumberFormatException.
> >> >>>> java:48)
> >> >>>>        at java.lang.Long.parseLong(Long.java:431)
> >> >>>>        at java.lang.Long.<init>(Long.java:678)
> >> >>>>        at
> >> >>>>
> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
> >> >>>> va:585)
> >> >>>>
> >> >>>> The problem in following code:
> >> >>>>
> >> >>>> public final Long toOptionalLong() throws
> >> StringValueConversionException
> >> >>>>    {
> >> >>>>        return (text == null) ? null : toLongObject();
> >> >>>>    }
> >> >>>>
> >> >>>> text should be checked for emptiness - not only null
> >> >>>>
> >> >>>> What do you think?
> >> >>>>
> >> >>>> Thanks,
> >> >>>>
> >> >>>> Ilia
> >> >>>>
> >> >>>
> >> >>>
> >> >>>
> >> >>> --
> >> >>> Martin Grigorov
> >> >>> jWeekend
> >> >>> Training, Consulting, Development
> >> >>> http://jWeekend.com
> >> >>>
> >> >>>
> ---------------------------------------------------------------------
> >> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >> >>>
> >> >>>
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> thank you,
> >> >>
> >> >> regards,
> >> >> Vineet Semwal
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> >> For additional commands, e-mail: users-help@wicket.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Martin Grigorov
> >> > jWeekend
> >> > Training, Consulting, Development
> >> > http://jWeekend.com
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> > For additional commands, e-mail: users-help@wicket.apache.org
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> thank you,
> >>
> >> regards,
> >> Vineet Semwal
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: StringValue.toOptionalLong incorrect behavior

Posted by Martin Grigorov <mg...@apache.org>.
Ticket please!

2011/12/20 Илья Нарыжный <ph...@ydn.ru>:
> Hello,
>
> Up this topic. Are you planning to fix this functionality with
> toOptionalString?
>
> Thanks,
>
> Ilis
>
> 2011/11/16 vineet semwal <vi...@gmail.com>
>
>>  yeah not needed for toOptionalString() but why not for
>> toOptionalBoolean()?
>>
>> On Wed, Nov 16, 2011 at 3:39 PM, Martin Grigorov <mg...@apache.org>
>> wrote:
>> > Hi,
>> >
>> > On Wed, Nov 16, 2011 at 11:50 AM, vineet semwal
>> > <vi...@gmail.com> wrote:
>> >> martin i too think tooptionalMethods in StringValue should behave the
>> >> way llia is saying ie. they should return null if text is empty or
>> >> null..
>> >
>> > Hm. Not quite convinced.
>> > ?a=b&c=&e=f is a valid query string and 'c' has value "" while 'g' has
>> null
>> >
>> > maybe just some of toOptionalXyz() methods should use Strings.isEmpty()
>> > e.g. toOptionalString() and toOptionalBoolean() should not check for ""
>> >
>> >> for eg. currently  public final Long toOptionalLong() throws
>> >> StringValueConversionException
>> >>        {
>> >>                return (text == null) ? null : toLongObject();
>> >>        }
>> >>
>> >> can be changed to
>> >>  public final Long toOptionalLong() throws
>> StringValueConversionException
>> >>        {
>> >>                return (Strings.isEmpty(text)) ? null : toLongObject();
>> >>        }
>> >>
>> >> On Wed, Nov 16, 2011 at 2:57 PM, Martin Grigorov <mg...@apache.org>
>> wrote:
>> >>> Hi,
>> >>>
>> >>> At least this is what the javadoc says:
>> >>> "Convert to object types, returning null if text is null."
>> >>>
>> >>> I think the more appropriate method for you is
>> >>> org.apache.wicket.util.string.StringValue.toLong(long) but it also
>> >>> throws exceptions if the provided value is empty string.
>> >>>
>> >>> On Wed, Nov 16, 2011 at 11:00 AM, Илья Нарыжный <ph...@ydn.ru>
>> wrote:
>> >>>> Hello,
>> >>>>
>> >>>> I have page mounted as @MountPath("/page/#{pageId}")
>> >>>>
>> >>>> Also I have following code:
>> >>>>
>> >>>> public ViewPagePage(PageParameters params)
>> >>>>    {
>> >>>>        this(getEntityPkFor(params, Page.class, 1)); //1 - is default
>> ID if
>> >>>> PK in url was not found
>> >>>>    }
>> >>>>
>> >>>> and:
>> >>>>
>> >>>> protected static Long getEntityPkFor(PageParameters params, Class
>> clazz,
>> >>>> Long defaultPk)
>> >>>>    {
>> >>>>        String pkFieldName =
>> EntitiesDescriptor.get().getPkFieldName(clazz);
>> >>>>        Long ret=null;
>> >>>>        if(pkFieldName!=null)
>> >>>>        {
>> >>>>            ret = params.get(pkFieldName).toOptionalLong();
>> >>>>        }
>> >>>>        if(ret==null)
>> >>>>        {
>> >>>>            ret = params.get("id").toOptionalLong();
>> >>>>        }
>> >>>>        return ret==null?defaultPk:ret;
>> >>>>    }
>> >>>>
>> >>>> But(!!!) if ID was not put to the URL I have following Exception:
>> >>>>
>> >>>> Caused by:
>> org.apache.wicket.util.string.StringValueConversionException:
>> >>>> Unable
>> >>>> to convert '' to a Long value
>> >>>>        at
>> >>>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
>> >>>> va:589)
>> >>>>        at
>> >>>> org.apache.wicket.util.string.StringValue.toOptionalLong(StringValue.
>> >>>> java:657)
>> >>>>        at ru.ydn.wicket.EntityPage.getEntityPkFor(EntityPage.java:57)
>> >>>>        at ru.ydn.wicket.web.ViewPagePage.<init>(ViewPagePage.java:84)
>> >>>>        ... 37 more
>> >>>> Caused by: java.lang.NumberFormatException: For input string: ""
>> >>>>        at
>> >>>> java.lang.NumberFormatException.forInputString(NumberFormatException.
>> >>>> java:48)
>> >>>>        at java.lang.Long.parseLong(Long.java:431)
>> >>>>        at java.lang.Long.<init>(Long.java:678)
>> >>>>        at
>> >>>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
>> >>>> va:585)
>> >>>>
>> >>>> The problem in following code:
>> >>>>
>> >>>> public final Long toOptionalLong() throws
>> StringValueConversionException
>> >>>>    {
>> >>>>        return (text == null) ? null : toLongObject();
>> >>>>    }
>> >>>>
>> >>>> text should be checked for emptiness - not only null
>> >>>>
>> >>>> What do you think?
>> >>>>
>> >>>> Thanks,
>> >>>>
>> >>>> Ilia
>> >>>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Martin Grigorov
>> >>> jWeekend
>> >>> Training, Consulting, Development
>> >>> http://jWeekend.com
>> >>>
>> >>> ---------------------------------------------------------------------
>> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >>> For additional commands, e-mail: users-help@wicket.apache.org
>> >>>
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> thank you,
>> >>
>> >> regards,
>> >> Vineet Semwal
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Martin Grigorov
>> > jWeekend
>> > Training, Consulting, Development
>> > http://jWeekend.com
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> > For additional commands, e-mail: users-help@wicket.apache.org
>> >
>> >
>>
>>
>>
>> --
>> thank you,
>>
>> regards,
>> Vineet Semwal
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StringValue.toOptionalLong incorrect behavior

Posted by Илья Нарыжный <ph...@ydn.ru>.
Hello,

Up this topic. Are you planning to fix this functionality with
toOptionalString?

Thanks,

Ilis

2011/11/16 vineet semwal <vi...@gmail.com>

>  yeah not needed for toOptionalString() but why not for
> toOptionalBoolean()?
>
> On Wed, Nov 16, 2011 at 3:39 PM, Martin Grigorov <mg...@apache.org>
> wrote:
> > Hi,
> >
> > On Wed, Nov 16, 2011 at 11:50 AM, vineet semwal
> > <vi...@gmail.com> wrote:
> >> martin i too think tooptionalMethods in StringValue should behave the
> >> way llia is saying ie. they should return null if text is empty or
> >> null..
> >
> > Hm. Not quite convinced.
> > ?a=b&c=&e=f is a valid query string and 'c' has value "" while 'g' has
> null
> >
> > maybe just some of toOptionalXyz() methods should use Strings.isEmpty()
> > e.g. toOptionalString() and toOptionalBoolean() should not check for ""
> >
> >> for eg. currently  public final Long toOptionalLong() throws
> >> StringValueConversionException
> >>        {
> >>                return (text == null) ? null : toLongObject();
> >>        }
> >>
> >> can be changed to
> >>  public final Long toOptionalLong() throws
> StringValueConversionException
> >>        {
> >>                return (Strings.isEmpty(text)) ? null : toLongObject();
> >>        }
> >>
> >> On Wed, Nov 16, 2011 at 2:57 PM, Martin Grigorov <mg...@apache.org>
> wrote:
> >>> Hi,
> >>>
> >>> At least this is what the javadoc says:
> >>> "Convert to object types, returning null if text is null."
> >>>
> >>> I think the more appropriate method for you is
> >>> org.apache.wicket.util.string.StringValue.toLong(long) but it also
> >>> throws exceptions if the provided value is empty string.
> >>>
> >>> On Wed, Nov 16, 2011 at 11:00 AM, Илья Нарыжный <ph...@ydn.ru>
> wrote:
> >>>> Hello,
> >>>>
> >>>> I have page mounted as @MountPath("/page/#{pageId}")
> >>>>
> >>>> Also I have following code:
> >>>>
> >>>> public ViewPagePage(PageParameters params)
> >>>>    {
> >>>>        this(getEntityPkFor(params, Page.class, 1)); //1 - is default
> ID if
> >>>> PK in url was not found
> >>>>    }
> >>>>
> >>>> and:
> >>>>
> >>>> protected static Long getEntityPkFor(PageParameters params, Class
> clazz,
> >>>> Long defaultPk)
> >>>>    {
> >>>>        String pkFieldName =
> EntitiesDescriptor.get().getPkFieldName(clazz);
> >>>>        Long ret=null;
> >>>>        if(pkFieldName!=null)
> >>>>        {
> >>>>            ret = params.get(pkFieldName).toOptionalLong();
> >>>>        }
> >>>>        if(ret==null)
> >>>>        {
> >>>>            ret = params.get("id").toOptionalLong();
> >>>>        }
> >>>>        return ret==null?defaultPk:ret;
> >>>>    }
> >>>>
> >>>> But(!!!) if ID was not put to the URL I have following Exception:
> >>>>
> >>>> Caused by:
> org.apache.wicket.util.string.StringValueConversionException:
> >>>> Unable
> >>>> to convert '' to a Long value
> >>>>        at
> >>>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
> >>>> va:589)
> >>>>        at
> >>>> org.apache.wicket.util.string.StringValue.toOptionalLong(StringValue.
> >>>> java:657)
> >>>>        at ru.ydn.wicket.EntityPage.getEntityPkFor(EntityPage.java:57)
> >>>>        at ru.ydn.wicket.web.ViewPagePage.<init>(ViewPagePage.java:84)
> >>>>        ... 37 more
> >>>> Caused by: java.lang.NumberFormatException: For input string: ""
> >>>>        at
> >>>> java.lang.NumberFormatException.forInputString(NumberFormatException.
> >>>> java:48)
> >>>>        at java.lang.Long.parseLong(Long.java:431)
> >>>>        at java.lang.Long.<init>(Long.java:678)
> >>>>        at
> >>>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
> >>>> va:585)
> >>>>
> >>>> The problem in following code:
> >>>>
> >>>> public final Long toOptionalLong() throws
> StringValueConversionException
> >>>>    {
> >>>>        return (text == null) ? null : toLongObject();
> >>>>    }
> >>>>
> >>>> text should be checked for emptiness - not only null
> >>>>
> >>>> What do you think?
> >>>>
> >>>> Thanks,
> >>>>
> >>>> Ilia
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Martin Grigorov
> >>> jWeekend
> >>> Training, Consulting, Development
> >>> http://jWeekend.com
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>
> >>
> >>
> >> --
> >> thank you,
> >>
> >> regards,
> >> Vineet Semwal
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> >
> >
> > --
> > Martin Grigorov
> > jWeekend
> > Training, Consulting, Development
> > http://jWeekend.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
>
> --
> thank you,
>
> regards,
> Vineet Semwal
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: StringValue.toOptionalLong incorrect behavior

Posted by vineet semwal <vi...@gmail.com>.
 yeah not needed for toOptionalString() but why not for toOptionalBoolean()?

On Wed, Nov 16, 2011 at 3:39 PM, Martin Grigorov <mg...@apache.org> wrote:
> Hi,
>
> On Wed, Nov 16, 2011 at 11:50 AM, vineet semwal
> <vi...@gmail.com> wrote:
>> martin i too think tooptionalMethods in StringValue should behave the
>> way llia is saying ie. they should return null if text is empty or
>> null..
>
> Hm. Not quite convinced.
> ?a=b&c=&e=f is a valid query string and 'c' has value "" while 'g' has null
>
> maybe just some of toOptionalXyz() methods should use Strings.isEmpty()
> e.g. toOptionalString() and toOptionalBoolean() should not check for ""
>
>> for eg. currently  public final Long toOptionalLong() throws
>> StringValueConversionException
>>        {
>>                return (text == null) ? null : toLongObject();
>>        }
>>
>> can be changed to
>>  public final Long toOptionalLong() throws StringValueConversionException
>>        {
>>                return (Strings.isEmpty(text)) ? null : toLongObject();
>>        }
>>
>> On Wed, Nov 16, 2011 at 2:57 PM, Martin Grigorov <mg...@apache.org> wrote:
>>> Hi,
>>>
>>> At least this is what the javadoc says:
>>> "Convert to object types, returning null if text is null."
>>>
>>> I think the more appropriate method for you is
>>> org.apache.wicket.util.string.StringValue.toLong(long) but it also
>>> throws exceptions if the provided value is empty string.
>>>
>>> On Wed, Nov 16, 2011 at 11:00 AM, Илья Нарыжный <ph...@ydn.ru> wrote:
>>>> Hello,
>>>>
>>>> I have page mounted as @MountPath("/page/#{pageId}")
>>>>
>>>> Also I have following code:
>>>>
>>>> public ViewPagePage(PageParameters params)
>>>>    {
>>>>        this(getEntityPkFor(params, Page.class, 1)); //1 - is default ID if
>>>> PK in url was not found
>>>>    }
>>>>
>>>> and:
>>>>
>>>> protected static Long getEntityPkFor(PageParameters params, Class clazz,
>>>> Long defaultPk)
>>>>    {
>>>>        String pkFieldName = EntitiesDescriptor.get().getPkFieldName(clazz);
>>>>        Long ret=null;
>>>>        if(pkFieldName!=null)
>>>>        {
>>>>            ret = params.get(pkFieldName).toOptionalLong();
>>>>        }
>>>>        if(ret==null)
>>>>        {
>>>>            ret = params.get("id").toOptionalLong();
>>>>        }
>>>>        return ret==null?defaultPk:ret;
>>>>    }
>>>>
>>>> But(!!!) if ID was not put to the URL I have following Exception:
>>>>
>>>> Caused by: org.apache.wicket.util.string.StringValueConversionException:
>>>> Unable
>>>> to convert '' to a Long value
>>>>        at
>>>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
>>>> va:589)
>>>>        at
>>>> org.apache.wicket.util.string.StringValue.toOptionalLong(StringValue.
>>>> java:657)
>>>>        at ru.ydn.wicket.EntityPage.getEntityPkFor(EntityPage.java:57)
>>>>        at ru.ydn.wicket.web.ViewPagePage.<init>(ViewPagePage.java:84)
>>>>        ... 37 more
>>>> Caused by: java.lang.NumberFormatException: For input string: ""
>>>>        at
>>>> java.lang.NumberFormatException.forInputString(NumberFormatException.
>>>> java:48)
>>>>        at java.lang.Long.parseLong(Long.java:431)
>>>>        at java.lang.Long.<init>(Long.java:678)
>>>>        at
>>>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
>>>> va:585)
>>>>
>>>> The problem in following code:
>>>>
>>>> public final Long toOptionalLong() throws StringValueConversionException
>>>>    {
>>>>        return (text == null) ? null : toLongObject();
>>>>    }
>>>>
>>>> text should be checked for emptiness - not only null
>>>>
>>>> What do you think?
>>>>
>>>> Thanks,
>>>>
>>>> Ilia
>>>>
>>>
>>>
>>>
>>> --
>>> Martin Grigorov
>>> jWeekend
>>> Training, Consulting, Development
>>> http://jWeekend.com
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>>
>> --
>> thank you,
>>
>> regards,
>> Vineet Semwal
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
thank you,

regards,
Vineet Semwal

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StringValue.toOptionalLong incorrect behavior

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Wed, Nov 16, 2011 at 11:50 AM, vineet semwal
<vi...@gmail.com> wrote:
> martin i too think tooptionalMethods in StringValue should behave the
> way llia is saying ie. they should return null if text is empty or
> null..

Hm. Not quite convinced.
?a=b&c=&e=f is a valid query string and 'c' has value "" while 'g' has null

maybe just some of toOptionalXyz() methods should use Strings.isEmpty()
e.g. toOptionalString() and toOptionalBoolean() should not check for ""

> for eg. currently  public final Long toOptionalLong() throws
> StringValueConversionException
>        {
>                return (text == null) ? null : toLongObject();
>        }
>
> can be changed to
>  public final Long toOptionalLong() throws StringValueConversionException
>        {
>                return (Strings.isEmpty(text)) ? null : toLongObject();
>        }
>
> On Wed, Nov 16, 2011 at 2:57 PM, Martin Grigorov <mg...@apache.org> wrote:
>> Hi,
>>
>> At least this is what the javadoc says:
>> "Convert to object types, returning null if text is null."
>>
>> I think the more appropriate method for you is
>> org.apache.wicket.util.string.StringValue.toLong(long) but it also
>> throws exceptions if the provided value is empty string.
>>
>> On Wed, Nov 16, 2011 at 11:00 AM, Илья Нарыжный <ph...@ydn.ru> wrote:
>>> Hello,
>>>
>>> I have page mounted as @MountPath("/page/#{pageId}")
>>>
>>> Also I have following code:
>>>
>>> public ViewPagePage(PageParameters params)
>>>    {
>>>        this(getEntityPkFor(params, Page.class, 1)); //1 - is default ID if
>>> PK in url was not found
>>>    }
>>>
>>> and:
>>>
>>> protected static Long getEntityPkFor(PageParameters params, Class clazz,
>>> Long defaultPk)
>>>    {
>>>        String pkFieldName = EntitiesDescriptor.get().getPkFieldName(clazz);
>>>        Long ret=null;
>>>        if(pkFieldName!=null)
>>>        {
>>>            ret = params.get(pkFieldName).toOptionalLong();
>>>        }
>>>        if(ret==null)
>>>        {
>>>            ret = params.get("id").toOptionalLong();
>>>        }
>>>        return ret==null?defaultPk:ret;
>>>    }
>>>
>>> But(!!!) if ID was not put to the URL I have following Exception:
>>>
>>> Caused by: org.apache.wicket.util.string.StringValueConversionException:
>>> Unable
>>> to convert '' to a Long value
>>>        at
>>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
>>> va:589)
>>>        at
>>> org.apache.wicket.util.string.StringValue.toOptionalLong(StringValue.
>>> java:657)
>>>        at ru.ydn.wicket.EntityPage.getEntityPkFor(EntityPage.java:57)
>>>        at ru.ydn.wicket.web.ViewPagePage.<init>(ViewPagePage.java:84)
>>>        ... 37 more
>>> Caused by: java.lang.NumberFormatException: For input string: ""
>>>        at
>>> java.lang.NumberFormatException.forInputString(NumberFormatException.
>>> java:48)
>>>        at java.lang.Long.parseLong(Long.java:431)
>>>        at java.lang.Long.<init>(Long.java:678)
>>>        at
>>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
>>> va:585)
>>>
>>> The problem in following code:
>>>
>>> public final Long toOptionalLong() throws StringValueConversionException
>>>    {
>>>        return (text == null) ? null : toLongObject();
>>>    }
>>>
>>> text should be checked for emptiness - not only null
>>>
>>> What do you think?
>>>
>>> Thanks,
>>>
>>> Ilia
>>>
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
> --
> thank you,
>
> regards,
> Vineet Semwal
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StringValue.toOptionalLong incorrect behavior

Posted by vineet semwal <vi...@gmail.com>.
martin i too think tooptionalMethods in StringValue should behave the
way llia is saying ie. they should return null if text is empty or
null..
for eg. currently  public final Long toOptionalLong() throws
StringValueConversionException
	{
		return (text == null) ? null : toLongObject();
	}

can be changed to
  public final Long toOptionalLong() throws StringValueConversionException
	{
		return (Strings.isEmpty(text)) ? null : toLongObject();
	}

On Wed, Nov 16, 2011 at 2:57 PM, Martin Grigorov <mg...@apache.org> wrote:
> Hi,
>
> At least this is what the javadoc says:
> "Convert to object types, returning null if text is null."
>
> I think the more appropriate method for you is
> org.apache.wicket.util.string.StringValue.toLong(long) but it also
> throws exceptions if the provided value is empty string.
>
> On Wed, Nov 16, 2011 at 11:00 AM, Илья Нарыжный <ph...@ydn.ru> wrote:
>> Hello,
>>
>> I have page mounted as @MountPath("/page/#{pageId}")
>>
>> Also I have following code:
>>
>> public ViewPagePage(PageParameters params)
>>    {
>>        this(getEntityPkFor(params, Page.class, 1)); //1 - is default ID if
>> PK in url was not found
>>    }
>>
>> and:
>>
>> protected static Long getEntityPkFor(PageParameters params, Class clazz,
>> Long defaultPk)
>>    {
>>        String pkFieldName = EntitiesDescriptor.get().getPkFieldName(clazz);
>>        Long ret=null;
>>        if(pkFieldName!=null)
>>        {
>>            ret = params.get(pkFieldName).toOptionalLong();
>>        }
>>        if(ret==null)
>>        {
>>            ret = params.get("id").toOptionalLong();
>>        }
>>        return ret==null?defaultPk:ret;
>>    }
>>
>> But(!!!) if ID was not put to the URL I have following Exception:
>>
>> Caused by: org.apache.wicket.util.string.StringValueConversionException:
>> Unable
>> to convert '' to a Long value
>>        at
>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
>> va:589)
>>        at
>> org.apache.wicket.util.string.StringValue.toOptionalLong(StringValue.
>> java:657)
>>        at ru.ydn.wicket.EntityPage.getEntityPkFor(EntityPage.java:57)
>>        at ru.ydn.wicket.web.ViewPagePage.<init>(ViewPagePage.java:84)
>>        ... 37 more
>> Caused by: java.lang.NumberFormatException: For input string: ""
>>        at
>> java.lang.NumberFormatException.forInputString(NumberFormatException.
>> java:48)
>>        at java.lang.Long.parseLong(Long.java:431)
>>        at java.lang.Long.<init>(Long.java:678)
>>        at
>> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
>> va:585)
>>
>> The problem in following code:
>>
>> public final Long toOptionalLong() throws StringValueConversionException
>>    {
>>        return (text == null) ? null : toLongObject();
>>    }
>>
>> text should be checked for emptiness - not only null
>>
>> What do you think?
>>
>> Thanks,
>>
>> Ilia
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
thank you,

regards,
Vineet Semwal

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: StringValue.toOptionalLong incorrect behavior

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

At least this is what the javadoc says:
"Convert to object types, returning null if text is null."

I think the more appropriate method for you is
org.apache.wicket.util.string.StringValue.toLong(long) but it also
throws exceptions if the provided value is empty string.

On Wed, Nov 16, 2011 at 11:00 AM, Илья Нарыжный <ph...@ydn.ru> wrote:
> Hello,
>
> I have page mounted as @MountPath("/page/#{pageId}")
>
> Also I have following code:
>
> public ViewPagePage(PageParameters params)
>    {
>        this(getEntityPkFor(params, Page.class, 1)); //1 - is default ID if
> PK in url was not found
>    }
>
> and:
>
> protected static Long getEntityPkFor(PageParameters params, Class clazz,
> Long defaultPk)
>    {
>        String pkFieldName = EntitiesDescriptor.get().getPkFieldName(clazz);
>        Long ret=null;
>        if(pkFieldName!=null)
>        {
>            ret = params.get(pkFieldName).toOptionalLong();
>        }
>        if(ret==null)
>        {
>            ret = params.get("id").toOptionalLong();
>        }
>        return ret==null?defaultPk:ret;
>    }
>
> But(!!!) if ID was not put to the URL I have following Exception:
>
> Caused by: org.apache.wicket.util.string.StringValueConversionException:
> Unable
> to convert '' to a Long value
>        at
> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
> va:589)
>        at
> org.apache.wicket.util.string.StringValue.toOptionalLong(StringValue.
> java:657)
>        at ru.ydn.wicket.EntityPage.getEntityPkFor(EntityPage.java:57)
>        at ru.ydn.wicket.web.ViewPagePage.<init>(ViewPagePage.java:84)
>        ... 37 more
> Caused by: java.lang.NumberFormatException: For input string: ""
>        at
> java.lang.NumberFormatException.forInputString(NumberFormatException.
> java:48)
>        at java.lang.Long.parseLong(Long.java:431)
>        at java.lang.Long.<init>(Long.java:678)
>        at
> org.apache.wicket.util.string.StringValue.toLongObject(StringValue.ja
> va:585)
>
> The problem in following code:
>
> public final Long toOptionalLong() throws StringValueConversionException
>    {
>        return (text == null) ? null : toLongObject();
>    }
>
> text should be checked for emptiness - not only null
>
> What do you think?
>
> Thanks,
>
> Ilia
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org