Upload file with RecordEditForm

The SECS/GEM module does this with the following:
0. The stuff you're already doing in the form meta.

  1. Subclassing RecordEditForm
  2. Setting up a private final field to hold the FileUploadField:
    private FileUploadField uploadField;
  3. Overriding newEditorComponent to capture the value in the field:
    @Override
    protected Component newEditorComponent(String id, FormMeta formMeta, RecordEditMode mode, SRecordInstance record) {
        Component comp = super.newEditorComponent(id, formMeta, mode, record);
        if (formMeta.getField().equals(EquipmentRecord.SecsDefinitionFile)) {
            uploadField = (FileUploadField) ((AbstractFormComponentEditor<?>) comp).getFormComponent();
        }
  1. Overriding onSubmit and extracting the list of uploaded files:
List<FileUpload> fuList = uploadField.getModelObject();

The same general approach should work, though I'll echo Phil's general sentiment that the less engineering effort spent on wrangling Wicket the better.

3 Likes