Hello, Up this topic. Are you planning to fix this functionality with toOptionalString?
Thanks, Ilis 2011/11/16 vineet semwal <vineetsemwal1...@gmail.com> > yeah not needed for toOptionalString() but why not for > toOptionalBoolean()? > > On Wed, Nov 16, 2011 at 3:39 PM, Martin Grigorov <mgrigo...@apache.org> > wrote: > > Hi, > > > > On Wed, Nov 16, 2011 at 11:50 AM, vineet semwal > > <vineetsemwal1...@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 <mgrigo...@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, Илья Нарыжный <phan...@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-unsubscr...@wicket.apache.org > >>> For additional commands, e-mail: users-h...@wicket.apache.org > >>> > >>> > >> > >> > >> > >> -- > >> thank you, > >> > >> regards, > >> Vineet Semwal > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > >> For additional commands, e-mail: users-h...@wicket.apache.org > >> > >> > > > > > > > > -- > > Martin Grigorov > > jWeekend > > Training, Consulting, Development > > http://jWeekend.com > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > > For additional commands, e-mail: users-h...@wicket.apache.org > > > > > > > > -- > thank you, > > regards, > Vineet Semwal > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >