List of usage examples for com.google.gwt.user.client.ui FormPanel METHOD_POST
String METHOD_POST
To view the source code for com.google.gwt.user.client.ui FormPanel METHOD_POST.
Click Source Link
From source file:edu.cudenver.bios.glimmpse.client.panels.WizardPanel.java
License:Open Source License
/** * Create an empty matrix panel// w w w. jav a 2 s . c om */ public WizardPanel(WizardStepPanel[][] stepPanels, String[] stepGroupLabels) { VerticalPanel contentPanel = new VerticalPanel(); VerticalPanel leftPanel = new VerticalPanel(); // initialize the steps left panel stepsLeftPanel = new StepsLeftPanel(stepGroupLabels); // add the content panels to the deck int count = 0; for (WizardStepPanel[] stepPanelGroup : stepPanels) { for (WizardStepPanel stepPanel : stepPanelGroup) { wizardDeck.add(stepPanel); stepPanel.addStepStatusListener(this); } count++; if (count < stepPanels.length) wizardDeck.add(new GroupSeparatorPanel()); } // add navigation callbacks navPanel.addNavigationListener(this); enterStep(); // set up the form for saving study designs VerticalPanel saveFormContainer = new VerticalPanel(); saveFormContainer.add(dataHidden); saveFormContainer.add(filenameHidden); saveForm.setAction(SAVEAS_URL); saveForm.setMethod(FormPanel.METHOD_POST); saveForm.add(saveFormContainer); // layout the wizard panel //contentPanel.add(toolBar); leftPanel.add(stepsLeftPanel); leftPanel.add(createToolLinks()); contentPanel.add(wizardDeck); contentPanel.add(navPanel); panel.add(leftPanel); panel.add(contentPanel); panel.add(saveForm); // add style contentPanel.setStyleName(STYLE_CONTENT_PANEL); panel.setStyleName(STYLE_CONTENT_PANEL); // initialize initWidget(panel); }
From source file:edu.cudenver.bios.powercalculator.client.panels.StartPanel.java
License:Open Source License
public StartPanel(InputWizardStepListener wizard, int stepIndex) { VerticalPanel panel = new VerticalPanel(); // layout the widgets // add introductory text HTML header = new HTML(PowerCalculatorGUI.constants.textStartPanelHeader()); HTML description = new HTML(PowerCalculatorGUI.constants.textStartPanelDescription()); panel.add(header);// w w w .j a v a2 s . c o m panel.add(description); // create user input container VerticalPanel inputContainer = new VerticalPanel(); // template design mode Grid templateModeContainer = new Grid(1, 2); VerticalPanel templateTextContainer = new VerticalPanel(); templateTextContainer.add(new HTML("<b>Study Design Templates</b>")); templateTextContainer.add(new HTML( "Common study designs including ANOVA, ANCOVA, and MANOVA. For users less familiar with the general linear model")); templateModeContainer.setWidget(0, 0, templateTextContainer); Button templateGo = new Button("Go", new ClickHandler() { public void onClick(ClickEvent e) { for (StartListener listener : startListeners) listener.onTemplateMode(); } }); templateGo.setStyleName("startPanelGoButton"); templateModeContainer.setWidget(0, 1, templateGo); // matrix entry mode Grid matrixModeContainer = new Grid(1, 2); VerticalPanel matrixTextContainer = new VerticalPanel(); matrixTextContainer.add(new HTML("<b>Matrix Mode</b>")); matrixTextContainer.add(new HTML( "Directly enter matrix representation for the general linear model. For users who are more familiar with statistical methods.")); matrixModeContainer.setWidget(0, 0, matrixTextContainer); Button matrixGo = new Button("Go", new ClickHandler() { public void onClick(ClickEvent e) { for (StartListener listener : startListeners) listener.onMatrixMode(); } }); matrixGo.setStyleName("startPanelGoButton"); matrixModeContainer.setWidget(0, 1, matrixGo); // upload an existing study VerticalPanel uploadContainer = new VerticalPanel(); uploadContainer.add(new HTML("<b>Upload an Existing Study</b>")); uploadContainer.add(new HTML( "If you have previously saved a study design from Glimmpse, you may upload it here. Click browse to select your study design file.")); // build the upload form // for file upload, we need to use the POST method, and multipart MIME encoding. formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); formPanel.setAction(UPLOAD_URI); // panel to contain the contents of the submission form HorizontalPanel formContents = new HorizontalPanel(); // create an upload widget uploader.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent e) { String filename = uploader.getFilename(); if (filename == null || filename.isEmpty()) { Window.alert( "No filename specified. Please click the 'Browse' button and select a file for upload."); } else { formPanel.submit(); } } }); uploader.setName(FORM_TAG_FILE); formContents.add(uploader); formPanel.add(formContents); formPanel.addSubmitCompleteHandler(this); uploadContainer.add(formPanel); templateModeContainer.setStyleName("startPanelContainer"); matrixModeContainer.setStyleName("startPanelContainer"); uploadContainer.setStyleName("startPanelContainer"); inputContainer.add(templateModeContainer); inputContainer.add(matrixModeContainer); inputContainer.add(uploadContainer); panel.add(inputContainer); // add style header.setStyleName(PowerCalculatorConstants.STYLE_WIZARD_STEP_HEADER); description.setStyleName(PowerCalculatorConstants.STYLE_WIZARD_STEP_DESCRIPTION); panel.setStyleName(PowerCalculatorConstants.STYLE_WIZARD_STEP_PANEL); inputContainer.setStyleName(PowerCalculatorConstants.STYLE_WIZARD_STEP_INPUT_CONTAINER); initWidget(panel); }
From source file:edu.iastate.airl.semtus.client.SEMTUSWEBAPP.java
License:Open Source License
public FormPanel upload() { final FormPanel form = new FormPanel(); form.setAction(GWT.getModuleBaseURL() + "upload"); // Because we're going to add a FileUpload widget, we'll need to set the // form to use the POST method, and multipart MIME encoding. form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); // Create a panel to hold all of the form widgets. HorizontalPanel panel = new HorizontalPanel(); form.setWidget(panel);/*ww w. jav a2 s . co m*/ // Create a FileUpload widget. final FileUpload upload = new FileUpload(); upload.setName("uploadFormElement"); panel.add(upload); panel.add(new HTML(" ")); // Add a 'submit' button. panel.add(new Button("Upload", new ClickHandler() { public void onClick(ClickEvent event) { String filename = upload.getFilename(); if (filename.length() == 0) { Window.alert("No File Specified"); } else { form.submit(); } } })); panel.add(new HTML(" ")); // Add a 'Done' button. panel.add(new Button("Done", new ClickHandler() { public void onClick(ClickEvent event) { uploadBox.hide(); tabPanel.selectTab(0); } })); // Add an event handler to the form. form.addSubmitHandler(new FormPanel.SubmitHandler() { public void onSubmit(SubmitEvent event) { } }); form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { // Check if there's been an error in upload if (event.getResults() == null) { Window.alert( "Ontology Upload Failed. Please give us feedback [sushain.pandit@gmail.com] explaining the parameters of upload (filesize, format, etc) and we'll try to get it resolved asap."); } else if (event.getResults().toLowerCase().contains("file already exists")) { // if it's already present on // server, then we're just // fine. Window.alert( "You just uploaded this ontology. Please proceed to the workspace for text input. Thanks !"); } else if (event.getResults().toLowerCase().contains("error") || event.getResults().toLowerCase().contains("not available")) { // o'wise flag an error Window.alert( "Ontology Upload Failed. Please give us feedback [sushain.pandit@gmail.com] explaining the parameters of upload (filesize, format, etc) and we'll try to get it resolved asap."); } else { Window.alert(event.getResults()); Window.alert("Ontology Upload Successful"); } } }); return form; }
From source file:edu.stanford.bmir.protege.web.client.ui.projectmanager.ProjectRevisionBundleConverter.java
License:Open Source License
private void returnTObundle(String converted) { FormPanel form = new FormPanel("_blank"); form.setAction("http://localhost:8080/BundleQueryInterface/BundleQuery.jsp"); form.setMethod(FormPanel.METHOD_POST); Hidden onto = new Hidden("ontology", converted); form.add(onto);/* ww w. j av a 2 s .com*/ form.submit(); }
From source file:edu.ucdenver.bios.glimmpseweb.client.connector.PowerSvcConnector.java
License:Open Source License
/** * Create a new connector to the power service */// w w w . j a v a2 s .co m public PowerSvcConnector() { VerticalPanel panel = new VerticalPanel(); // set up the form for saving study designs VerticalPanel matrixFormContainer = new VerticalPanel(); matrixFormContainer.add(studyDesignHidden); matrixDisplayForm.setAction(GlimmpseWeb.constants.powerSvcHostMatricesAsHTML()); matrixDisplayForm.setMethod(FormPanel.METHOD_POST); matrixDisplayForm.addSubmitHandler(new SubmitHandler() { @Override public void onSubmit(SubmitEvent event) { Window.open("", MATRIX_DISPLAY_WINDOW, "width=600,height=500,location=no,toolbars=no,menubar=no,status=yes,resizable=yes,scrollbars=yes"); } }); matrixDisplayForm.add(matrixFormContainer); panel.add(matrixDisplayForm); initWidget(panel); }
From source file:edu.ucdenver.bios.glimmpseweb.client.shared.GlimmpseFeedbackPanel.java
License:Open Source License
public GlimmpseFeedbackPanel() { /* setup the hidden fields */ envReportHidden.setValue("REMOTE_HOST,REMOTE_ADDR," + "HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER"); goodUrlHidden.setValue("/feedbackSuccess.html"); badUrlHidden.setValue("/feedbackError.html"); recipientsHidden.setValue(GlimmpseWeb.constants.feedbackEmailAddress()); mailOptionsHidden.setValue("Exclude=email;realname"); VerticalPanel panel = new VerticalPanel(); HTML header = new HTML(GlimmpseWeb.constants.feedbackHeader()); HTML description = new HTML(GlimmpseWeb.constants.feedbackDescription()); // assign names to form widgets nameTextBox.setName("FullName"); emailAddressTextBox.setName("EmailAddr"); browserOtherTextBox.setName("browserOther"); versionListBox.setName("version"); messageTextArea.setName("message"); // build subject listbox subjectListBox.addItem(GlimmpseWeb.constants.feedbackTypeGeneral()); subjectListBox.addItem(GlimmpseWeb.constants.feedbackTypeFeature()); subjectListBox.addItem(GlimmpseWeb.constants.feedbackTypeBug()); subjectListBox.setName("subject"); // build browser listbox browserListBox.addItem(GlimmpseWeb.constants.browserChromeLabel()); browserListBox.addItem(GlimmpseWeb.constants.browserIELabel()); browserListBox.addItem(GlimmpseWeb.constants.browserFirefoxLabel()); browserListBox.addItem(GlimmpseWeb.constants.browserOperaLabel()); browserListBox.addItem(GlimmpseWeb.constants.browserSafariLabel()); browserListBox.addItem(GlimmpseWeb.constants.other()); browserListBox.setName("browser"); // build version listbox versionListBox.addItem("2.0.0 beta"); versionListBox.addItem("1.1.0"); versionListBox.addItem(GlimmpseWeb.constants.notSure()); // callbacks on radio buttons contactYesRadioButton.addClickHandler(new ClickHandler() { @Override// w ww . j a v a 2 s .com public void onClick(ClickEvent event) { setContact("Yes"); } }); contactNoRadioButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { setContact("No"); } }); // validation callbacks on required fields nameTextBox.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { checkComplete(); } }); emailAddressTextBox.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { TextBox tb = (TextBox) event.getSource(); try { TextValidation.parseEmail(tb.getText()); TextValidation.displayOkay(emailErrorHTML, ""); } catch (ParseException pe) { TextValidation.displayError(emailErrorHTML, GlimmpseWeb.constants.errorInvalidEmail()); tb.setText(""); } checkComplete(); } }); messageTextArea.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { checkComplete(); } }); // build the form feedbackForm.setAction(FORMMAIL_URI); feedbackForm.setMethod(FormPanel.METHOD_POST); VerticalPanel formContainer = new VerticalPanel(); // add hidden fields formContainer.add(envReportHidden); formContainer.add(goodUrlHidden); formContainer.add(badUrlHidden); formContainer.add(recipientsHidden); formContainer.add(mailOptionsHidden); formContainer.add(contactHidden); // select feature, bug, or comment formContainer.add(buildInputQuestion(GlimmpseWeb.constants.feedbackTypeLabel())); formContainer.add(subjectListBox); // enter name formContainer.add(buildInputQuestion(GlimmpseWeb.constants.feedbackNameLabel())); formContainer.add(nameTextBox); // enter email formContainer.add(buildInputQuestion(GlimmpseWeb.constants.feedbackEmailLabel())); HorizontalPanel emailPanel = new HorizontalPanel(); emailPanel.add(emailAddressTextBox); emailPanel.add(emailErrorHTML); formContainer.add(emailPanel); // enter if contact is okay formContainer.add(buildInputQuestion(GlimmpseWeb.constants.feedbackMayWeContactLabel())); Grid yesNoContainer = new Grid(1, 2); contactYesRadioButton.setValue(true); yesNoContainer.setWidget(0, 0, contactYesRadioButton); yesNoContainer.setWidget(0, 1, contactNoRadioButton); formContainer.add(yesNoContainer); // browser select with other formContainer.add(buildInputQuestion(GlimmpseWeb.constants.feedbackBrowserLabel())); formContainer.add(browserListBox); formContainer.add(buildInputQuestion(GlimmpseWeb.constants.feedbackOtherLabel())); formContainer.add(browserOtherTextBox); // version dropdown formContainer.add(buildInputQuestion(GlimmpseWeb.constants.feedbackVersionLabel())); formContainer.add(versionListBox); // actual message contents formContainer.add(buildInputQuestion(GlimmpseWeb.constants.feedbackContentsLabel())); formContainer.add(messageTextArea); formContainer.add(submitButton); // add the container to the form feedbackForm.setWidget(formContainer); // layout the overall panel panel.add(header); panel.add(description); panel.add(feedbackForm); // set style header.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_HEADER); description.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_DESCRIPTION); subjectListBox.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_RESPONSE); nameTextBox.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_RESPONSE); emailAddressTextBox.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_RESPONSE); yesNoContainer.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_RESPONSE); browserListBox.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_RESPONSE); browserOtherTextBox.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_RESPONSE); versionListBox.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_RESPONSE); messageTextArea.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_MESSAGE); submitButton.setStyleName(GlimmpseConstants.STYLE_FEEDBACK_SUBMIT); emailErrorHTML.setStyleName(GlimmpseConstants.STYLE_MESSAGE); checkComplete(); initWidget(panel); }
From source file:edu.ucdenver.bios.glimmpseweb.client.shared.ModeSelectionPanel.java
License:Open Source License
/** * Constructor//from w w w. j a v a 2 s . c om */ public ModeSelectionPanel() { VerticalPanel panel = new VerticalPanel(); HorizontalPanel selectPanel = new HorizontalPanel(); // build the working dialog buildWaitDialog(); // layout the widgets // add introductory text HTML header = new HTML(GlimmpseWeb.constants.modeSelectionTitle()); HTML description = new HTML(GlimmpseWeb.constants.modeSelectionDescription()); // create user input container Grid inputContainer = new Grid(1, 3); // guided study design mode VerticalPanel guidedModeContainer = new VerticalPanel(); HTML guidedTitle = new HTML(GlimmpseWeb.constants.modeSelectionGuidedTitle()); HTML guidedDescription = new HTML(GlimmpseWeb.constants.modeSelectionGuidedDescription()); Button guidedGoButton = new Button(GlimmpseWeb.constants.modeSelectionGoButton(), new ClickHandler() { public void onClick(ClickEvent e) { for (ModeSelectionHandler listener : modeSelectionHandlers) listener.onGuidedMode(); } }); guidedModeContainer.add(guidedTitle); guidedModeContainer.add(guidedDescription); guidedModeContainer.add(guidedGoButton); // matrix entry mode VerticalPanel matrixModeContainer = new VerticalPanel(); HTML matrixTitle = new HTML(GlimmpseWeb.constants.modeSelectionMatrixTitle()); HTML matrixDescription = new HTML(GlimmpseWeb.constants.modeSelectionMatrixDescription()); Button matrixGoButton = new Button(GlimmpseWeb.constants.modeSelectionGoButton(), new ClickHandler() { public void onClick(ClickEvent e) { for (ModeSelectionHandler listener : modeSelectionHandlers) listener.onMatrixMode(); } }); matrixModeContainer.add(matrixTitle); matrixModeContainer.add(matrixDescription); matrixModeContainer.add(matrixGoButton); // upload an existing study VerticalPanel uploadContainer = new VerticalPanel(); HTML uploadTitle = new HTML(GlimmpseWeb.constants.modeSelectionUploadTitle()); HTML uploadDescription = new HTML(GlimmpseWeb.constants.modeSelectionUploadDescription()); uploadContainer.add(uploadTitle); uploadContainer.add(uploadDescription); // build the upload form // for file upload, we need to use the POST method, and multipart MIME encoding. formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); formPanel.setAction(UPLOAD_URI); // panel to contain the contents of the submission form HorizontalPanel formContents = new HorizontalPanel(); // create an upload widget uploader.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent e) { String filename = uploader.getFilename(); if (filename == null || filename.isEmpty()) { Window.alert( "No filename specified. Please click the 'Browse' button and select a file for upload."); } else { showWorkingDialog(); formPanel.submit(); } } }); uploader.setName(FORM_TAG_FILE); formContents.add(uploader); formPanel.add(formContents); formPanel.addSubmitCompleteHandler(this); uploadContainer.add(formPanel); // build overall panel inputContainer.setWidget(0, 0, guidedModeContainer); inputContainer.setWidget(0, 1, matrixModeContainer); inputContainer.setWidget(0, 2, uploadContainer); panel.add(header); panel.add(description); panel.add(inputContainer); // add style header.setStyleName(STYLE_HEADER); description.setStyleName(STYLE_DESCRIPTION); panel.setStyleName(STYLE_PANEL); inputContainer.setStyleName(STYLE_INPUT_CONTAINER); // guided subpanel style guidedModeContainer.setStyleName(STYLE_CONTAINER); guidedTitle.setStyleName(STYLE_CONTAINER_TITLE); guidedDescription.setStyleName(STYLE_CONTAINER_DESC); guidedGoButton.setStyleName(STYLE_GO_BUTTON); // matrix subpanel style matrixModeContainer.setStyleName(STYLE_CONTAINER); matrixTitle.setStyleName(STYLE_CONTAINER_TITLE); matrixDescription.setStyleName(STYLE_CONTAINER_DESC); matrixGoButton.setStyleName(STYLE_GO_BUTTON); // upload subpanel style uploadContainer.setStyleName(STYLE_CONTAINER); uploadTitle.setStyleName(STYLE_CONTAINER_TITLE); uploadDescription.setStyleName(STYLE_CONTAINER_DESC); // initialize the panel initWidget(panel); }
From source file:edu.ucla.loni.client.ServerLibraryManager.java
License:Open Source License
/** * Sets workarea to an import form/*w ww. ja va 2 s . c o m*/ */ private void importForm() { clearWorkarea(); // Title Label title = new Label("Import File(s)"); title.setHeight(30); title.setStyleName("workarea-title"); // Uses GWT form components so we can submit in the background Grid grid = new Grid(4, 3); final FormPanel uploadForm = new FormPanel(); uploadForm.setWidget(grid); uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART); uploadForm.setMethod(FormPanel.METHOD_POST); uploadForm.setAction(GWT.getModuleBaseURL() + "upload"); // Package Name Label packageLabel = new Label("Package"); packageLabel.setHeight(30); final TextBox packageName = new TextBox(); packageName.setName("packageName"); packageName.setWidth("300px"); Label packageDescription = new Label("Set package to put all uploaded files into that package.<br/>" + "If empty all files will be placed in the package specified in the file"); packageDescription.setHeight(30); packageDescription.setWidth(500); packageDescription.setStyleName("workarea-description"); grid.setWidget(0, 0, packageLabel); grid.setWidget(0, 1, packageName); grid.setWidget(0, 2, packageDescription); // Upload local file Label uploadLabel = new Label("Upload Local Files"); uploadLabel.setHeight(40); FileUpload fileItem = new FileUpload(); fileItem.setName("theMostUniqueName"); Scheduler.get().scheduleDeferred(new Command() { @Override public void execute() { enableUpload(); //FROM :: http://forums.smartclient.com/showthread.php?t=16007 } }); Label uploadDescription = new Label( "Select local files to upload. Accepts \".pipe\" files only. All other files are discarded."); uploadDescription.setHeight(30); uploadDescription.setWidth(500); uploadDescription.setStyleName("workarea-description"); grid.setWidget(1, 0, uploadLabel); grid.setWidget(1, 1, fileItem); grid.setWidget(1, 2, uploadDescription); // Upload URLs Label urlLabel = new Label("Upload From URLs"); urlLabel.setHeight(40); final TextArea urls = new TextArea(); urls.setName("urls"); urls.setWidth("300px"); urls.setHeight("100px"); Label urlDescription = new Label("Enter a newline seperated list of urls."); urlDescription.setHeight(40); urlDescription.setWidth(400); urlDescription.setStyleName("workarea-description"); grid.setWidget(2, 0, urlLabel); grid.setWidget(2, 1, urls); grid.setWidget(2, 2, urlDescription); Button uploadButton = new Button("Send"); uploadButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { uploadForm.submit(); } }); grid.setWidget(3, 0, uploadButton); uploadForm.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { if (event.getResults().length() == 0) { success("Successfully uploaded files"); } else { error("Failed to upload files: " + event.getResults()); } updateFullTree(null); basicInstructions(); } }); // Root Directory Hidden hRoot = new Hidden(); hRoot.setName("root"); hRoot.setValue(rootDirectory.absolutePath); grid.setWidget(3, 1, hRoot); workarea.addMember(title); workarea.addMember(uploadForm); }
From source file:edu.umn.msi.tropix.webgui.client.widgets.GWTDownloadFormPanel.java
License:Open Source License
public void init(final String[] extraParameters) { // setMethod(FormMethod.POST); this.setMethod(FormPanel.METHOD_POST); // setEncoding(Encoding.NORMAL); this.setEncoding(FormPanel.ENCODING_URLENCODED); if (extraParameters != null) { for (final String extraParameter : extraParameters) { addExtraParameter(extraParameter); }/* w w w . j a v a 2s . c om*/ } try { this.vp.add(this.type); this.vp.add(this.id); this.setWidget(this.vp); } catch (final Exception e) { e.printStackTrace(); } this.parameters.put("downloadType", this.type); this.parameters.put("id", this.id); this.setType(GWTDownloadFormPanel.DOWNLOAD_TYPE_SIMPLE); }
From source file:es.deusto.weblab.client.lab.comm.LabCommunication.java
License:Open Source License
/** * Sends a file asynchronously. Upon doing the async request to the server, it will be internally stored * in the async requests manager, and polling will be done until the response is available. Then, the * specified callback will be notified with the result. *///from ww w. ja va 2s.com @Override public void sendAsyncFile(final SessionID sessionId, final UploadStructure uploadStructure, final IResponseCommandCallback callback) { // "Serialize" sessionId // We will now create the Hidden elements which we will use to pass // the required POST parameters to the web script that will actually handle // the file upload request. final Hidden sessionIdElement = new Hidden(); sessionIdElement.setName(LabCommunication.SESSION_ID_ATTR); sessionIdElement.setValue(sessionId.getRealId()); final Hidden fileInfoElement = new Hidden(); fileInfoElement.setName(LabCommunication.FILE_INFO_ATTR); fileInfoElement.setValue(uploadStructure.getFileInfo()); final Hidden isAsyncElement = new Hidden(); isAsyncElement.setName(LabCommunication.FILE_IS_ASYNC_ATTR); isAsyncElement.setValue("true"); // Set up uploadStructure uploadStructure.addInformation(sessionIdElement); uploadStructure.addInformation(fileInfoElement); uploadStructure.addInformation(isAsyncElement); uploadStructure.getFileUpload().setName(LabCommunication.FILE_SENT_ATTR); uploadStructure.getFormPanel().setAction(this.getFilePostUrl()); uploadStructure.getFormPanel().setEncoding(FormPanel.ENCODING_MULTIPART); uploadStructure.getFormPanel().setMethod(FormPanel.METHOD_POST); // Register handler uploadStructure.getFormPanel().addSubmitCompleteHandler(new SubmitCompleteHandler() { @Override public void onSubmitComplete(SubmitCompleteEvent event) { uploadStructure.removeInformation(sessionIdElement); final String resultMessage = event.getResults(); // resultMessage will be a string such as SUCCESS@34KJ2341KJ if (GWT.isScript() && resultMessage == null) { this.reportFail(callback); } else { this.processResultMessage(callback, resultMessage); } } private void processResultMessage(IResponseCommandCallback commandCallback, String resultMessage) { final ResponseCommand parsedRequestIdCommand; try { // TODO: This should be improved. if (!resultMessage.toLowerCase().startsWith("success@")) throw new SerializationException("Async send file response does not start with success@"); final String reslt = resultMessage.substring("success@".length()); System.out.println("[DBG]: AsyncSendFile returned: " + reslt); parsedRequestIdCommand = new ResponseCommand(reslt); } catch (final SerializationException e) { commandCallback.onFailure(e); return; } // } catch (final SessionNotFoundException e) { // commandCallback.onFailure(e); // return; // } catch (final WlServerException e) { // commandCallback.onFailure(e); // return; // } // We now have the request id of our asynchronous send_file request. // We will need to register the request with the asynchronous manager // so that it automatically polls and notifies us when the request finishes. final String requestID = parsedRequestIdCommand.getCommandString(); AsyncRequestsManager asyncReqMngr = LabCommunication.this.asyncRequestsManagers.get(sessionId); // TODO: Consider some better way of handling the managers. if (asyncReqMngr == null) asyncReqMngr = new AsyncRequestsManager(LabCommunication.this, sessionId, (ILabSerializer) LabCommunication.this.serializer); asyncReqMngr.registerAsyncRequest(requestID, commandCallback); } private void reportFail(final IResponseCommandCallback callback) { GWT.log("reportFail could not async send the file", null); callback.onFailure(new CommException("Couldn't async send the file")); } }); // Submit uploadStructure.getFormPanel().submit(); }