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, Илья Нарыжный <[email protected]> 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: [email protected] For additional commands, e-mail: [email protected]
