File Upload into Forms


Is it possible to integrate a file upload into Form Component ? I am extending the portlet AddressBook example.
Else is it possible to integrate it outside from a form ?

Best regards

Well, the Upload component is not a Field that you could add to a Form; you can’t bind it directly to a Property in the (Item) data model of the Form. You can add non-Field components to a Form with addComponent(), but they will not be bound to the Form data, so you’ll have to handle that manually.

All Fields have a value, as defined in the Property interface. The Upload component is not a Field, because it’s not quite clear what its “value” would be. It’s not sensible to keep uploaded files into memory, and the file name is not unique as it is different in the uploader’s computer and in the server’s filesystem to which its written. That said, one solution is that you extend the Upload component and implement the Field (and Property) interface, so that you could use it in a Form. In that case, you could, for example, save the uploaded field to a file and the name (and path) of that file as the property value. Implementing Field could take some effort though, maybe some other solution is easier. Well, I’m not quite sure what you want to do.