use of com.extjs.gxt.ui.client.widget.form.FileUploadField in project kapua by eclipse.
the class SSLFileUploadDialog method onRender.
@Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
setLayout(new FormLayout());
setBodyBorder(false);
setModal(true);
setButtons("");
setAutoWidth(true);
setScrollMode(Scroll.AUTO);
setHideOnButtonClick(false);
m_formPanel = new FormPanel();
m_formPanel.setFrame(false);
m_formPanel.setHeaderVisible(false);
m_formPanel.setBodyBorder(false);
m_formPanel.setAction(m_url);
m_formPanel.setEncoding(Encoding.MULTIPART);
m_formPanel.setMethod(Method.POST);
m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
HiddenField<Boolean> success = new HiddenField<Boolean>();
@Override
public void handleEvent(FormEvent be) {
String htmlResponse = be.getResultHtml();
if (htmlResponse == null || htmlResponse.isEmpty()) {
success = new HiddenField<Boolean>();
success.setName("success");
success.setValue(true);
m_hiddenFields.set(0, success);
} else {
String errMsg = htmlResponse;
int startIdx = htmlResponse.indexOf("<pre>");
int endIndex = htmlResponse.indexOf("</pre>");
if (startIdx != -1 && endIndex != -1) {
errMsg = htmlResponse.substring(startIdx + 5, endIndex);
}
MessageBox.alert(MSGS.error(), MSGS.fileUploadFailure() + ": " + errMsg, null);
success = new HiddenField<Boolean>();
success.setName("success");
success.setValue(false);
m_hiddenFields.set(0, success);
}
hide();
}
});
m_fileUploadFieldCert = new FileUploadField();
m_fileUploadFieldCert.setAllowBlank(false);
m_fileUploadFieldCert.setName("uploadedSSLCert");
m_fileUploadFieldCert.setFieldLabel("SSL Certificate");
m_formPanel.add(m_fileUploadFieldCert);
m_fileUploadFieldKey = new FileUploadField();
m_fileUploadFieldKey.setAllowBlank(false);
m_fileUploadFieldKey.setName("uploadedSSLKey");
m_fileUploadFieldKey.setFieldLabel("SSL Key");
m_formPanel.add(m_fileUploadFieldKey);
if (m_hiddenFields != null) {
for (HiddenField<?> hf : m_hiddenFields) {
m_formPanel.add(hf);
}
}
//
// xsrfToken Hidden field
//
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
xsrfTokenField.setValue(token.getToken());
}
});
xsrfTokenField = new HiddenField<String>();
xsrfTokenField.setId("xsrfToken");
xsrfTokenField.setName("xsrfToken");
xsrfTokenField.setValue("");
// Add the xsrf hidden field to the form panel
m_formPanel.add(xsrfTokenField);
add(m_formPanel);
}
Aggregations