FireGlow
25 May 2009, 4:19 AM
Hey guys!
I'm wondering how to realise a FileUpload with ExtGWT.
I tried this way:
public class ArchetypeImportForm
extends FormPanel
{
private static EHRflexMessages messages = GWTServiceFactory.getEHRflexMessages();
private Button okButton;
private EHRflexFileUploadField archetypeFile = new EHRflexFileUploadField(messages.ehrflex_file(), false);
private ArchetypeDataModel archetypeDataModel;
/**
* EventListener vor login button. It start's the log in process.
*/
private Listener<ButtonEvent> okButtonListener = new Listener<ButtonEvent>() {
public void handleEvent( ButtonEvent buttonEvent ) {
doUpload();
}
};
public void doUpload()
{
if(this.isValid())
{
//TODO: Fieldbinding would be better, but doesn't work that easily
this.archetypeDataModel.setFilePath((String) archetypeFile.getValue());
Dispatcher.get().dispatch( new EHRflexEvent<ArchetypeDataModel>( EHRflexEventType.ARCHETYPE_IMPORT_SUBMIT, archetypeDataModel) );
}
}
/**
* Creates thelogiform with all needed fields and fielbindings to a empty datamodel
*/
public ArchetypeImportForm() {
this.setLabelWidth( 80 );
this.setHeaderVisible(false);
this.setFieldWidth(400);
archetypeDataModel = new ArchetypeDataModel();
// LoginButton
this.okButton = new Button( messages.ehrflex_doUpload());
this.okButton.addListener( Events.OnClick, okButtonListener );
this.okButton.setIconStyle("icon-upload");
// For Button
FieldSet button = new FieldSet();
button.setLayout( new RowLayout( Style.Orientation.HORIZONTAL ) );
button.setHeight( 32 );
button.setBorders( false );
button.add( this.okButton );
// Adding components
this.add(archetypeFile);
this.add( button );
}
}
The Dispatcher transmits a asynccallback to the ArchetypeGWTServiceImpl#importArchetype:
public class ArchetypeGWTServiceImpl extends EHRflexRemoteServiceServlet
implements ArchetypeGWTService {
private ArchetypeService archetypeService = ArchetypeServiceImpl.getInstance();
/**
* @see ArchetypeGWTService#importArchetype(ArchetypeDataModel, String)
*/
public void importArchetype(ArchetypeDataModel archetype,
String sharedSecret) throws EHRflexException {
System.out.println(archetype.getFilePath());
File archetypeFile = new File(archetype.getFilePath());
this.archetypeService.importArchetype(archetypeFile);
}
}
ArchetypeDataModel contains only the filepath as a String.
It works, but I'm wondering if it will work if the client is not the server? I think it doesn't, but how to realise a FileUpload using GWTServices and without reloading the whole website (if you use submit()) ?
Thanks for helping!
I'm wondering how to realise a FileUpload with ExtGWT.
I tried this way:
public class ArchetypeImportForm
extends FormPanel
{
private static EHRflexMessages messages = GWTServiceFactory.getEHRflexMessages();
private Button okButton;
private EHRflexFileUploadField archetypeFile = new EHRflexFileUploadField(messages.ehrflex_file(), false);
private ArchetypeDataModel archetypeDataModel;
/**
* EventListener vor login button. It start's the log in process.
*/
private Listener<ButtonEvent> okButtonListener = new Listener<ButtonEvent>() {
public void handleEvent( ButtonEvent buttonEvent ) {
doUpload();
}
};
public void doUpload()
{
if(this.isValid())
{
//TODO: Fieldbinding would be better, but doesn't work that easily
this.archetypeDataModel.setFilePath((String) archetypeFile.getValue());
Dispatcher.get().dispatch( new EHRflexEvent<ArchetypeDataModel>( EHRflexEventType.ARCHETYPE_IMPORT_SUBMIT, archetypeDataModel) );
}
}
/**
* Creates thelogiform with all needed fields and fielbindings to a empty datamodel
*/
public ArchetypeImportForm() {
this.setLabelWidth( 80 );
this.setHeaderVisible(false);
this.setFieldWidth(400);
archetypeDataModel = new ArchetypeDataModel();
// LoginButton
this.okButton = new Button( messages.ehrflex_doUpload());
this.okButton.addListener( Events.OnClick, okButtonListener );
this.okButton.setIconStyle("icon-upload");
// For Button
FieldSet button = new FieldSet();
button.setLayout( new RowLayout( Style.Orientation.HORIZONTAL ) );
button.setHeight( 32 );
button.setBorders( false );
button.add( this.okButton );
// Adding components
this.add(archetypeFile);
this.add( button );
}
}
The Dispatcher transmits a asynccallback to the ArchetypeGWTServiceImpl#importArchetype:
public class ArchetypeGWTServiceImpl extends EHRflexRemoteServiceServlet
implements ArchetypeGWTService {
private ArchetypeService archetypeService = ArchetypeServiceImpl.getInstance();
/**
* @see ArchetypeGWTService#importArchetype(ArchetypeDataModel, String)
*/
public void importArchetype(ArchetypeDataModel archetype,
String sharedSecret) throws EHRflexException {
System.out.println(archetype.getFilePath());
File archetypeFile = new File(archetype.getFilePath());
this.archetypeService.importArchetype(archetypeFile);
}
}
ArchetypeDataModel contains only the filepath as a String.
It works, but I'm wondering if it will work if the client is not the server? I think it doesn't, but how to realise a FileUpload using GWTServices and without reloading the whole website (if you use submit()) ?
Thanks for helping!