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