Details
Description
This was detected when using the example/sample Upload demo locally.
ERROR - RequestCycle - there was an error cleaning up target org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget@20665159[Page class = org.apache.wicket.examples.upload.UploadPage, id = 0, version = 0]>simpleUpload->interface org.apache.wicket.markup.html.form.IFormSubmitListener.IFormSubmitListener (request paramaters: [RequestParameters componentPath=0:simpleUpload pageMapName=null versionNumber=0 interfaceName=IFormSubmitListener componentId=null behaviorId=null urlDepth=-1 parameters={} onlyProcessIfPathActive=false]).
java.lang.IllegalStateException: Attempt to set model object on null model of component: simpleUpload:fileInput
at org.apache.wicket.Component.setDefaultModelObject(Component.java:2962)
at org.apache.wicket.markup.html.form.FormComponent.setModelObject(FormComponent.java:1652)
at org.apache.wicket.markup.html.form.upload.FileUploadField.onDetach(FileUploadField.java:175)
Looking at the source indicates that unless onDetach() is over-ridden the default will always generate this exception. Here is the source for the FileUpLoadField.onDetach(). The line that creates the exception is noted by the "<<<HERE" in the snippet below.
FileUpLoadField.onDetach() snippet:
/**
- Clean up at the end of the request. This means closing all inputstreams which might have been
- opened from the fileUpload.
- @see org.apache.wicket.Component#onDetach()
*/
@Override
protected void onDetach()Unknown macro: { if (fileUpload != null && forceCloseStreamsOnDetach()) { fileUpload.closeStreams(); fileUpload = null; setModelObject(null); <<<HERE } super.onDetach(); }
Drilling further down, the setModelObject() calls FormComponent.setModelObject(), which in turns calls Component.setDefaultModelObject(). Inside setDefaultModelObject(), a check is done to see if the model object is null, if it is, it throws an exception:
public final Component setDefaultModelObject(final Object object)
{
final IModel<Object> model = (IModel<Object>)getDefaultModel();
// Check whether anything can be set at all
if (model == null)
...
}