Uploading files
To provide the user the option of uploading files ROMA provides a set of facilities. The class Stream of org.romaframework.core.domain.type contains an InputStream and some information about the stream. This class can be rendered as an upload dialog with the annotation render = "upload". In the case of Cantiga there is an attribute in MusicalContent called stream which represents the file with the musical content:
@ViewField(render = "upload", visible=AnnotationConstants.FALSE)
private Stream stream;
This attribute is not visible by default because we only wan to show it in upload operations (and not, for example, in searches). After [generate the CRUD] of MusicalContent. It must be modified the auto-generated class MusicalContentInstance which is the class used to display MusicalContent instances on CRUD creation. We must initialize the variable entity in the constructor to avoid null pointer exceptions in execution time. The next step is to create a get method for the
public MusicalContentInstance(){
entity = new MusicalContent();
}
And add a getter method for the stream to be displayed:
@ViewField(render = "upload")
public Stream getStream() {
return entity.getStream();
}
When the user click on the Browse button and select the file to upload, Roma will handle the HTTP request. After that, the method onStream() is called so it can be added parse operations overriding this method in the MusicalContentInstance:
class public void onStream() {
System.out.println("uploaded!");
}
Last Update: 2008-08-13
| << Prev | Cantiga | Next>> |
0 Ficheros adjuntos