0

私はこのクラスを使用しています:

/**
 * 
 */
package com.xerox.tclg.ejuror.ui.client;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FormEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.extjs.gxt.ui.client.widget.form.FileUploadField;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.FormPanel.Encoding;
import com.extjs.gxt.ui.client.widget.form.FormPanel.Method;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Image;
import com.xerox.tclg.ejuror.ui.client.service.PersonViewService;
import com.xerox.tclg.ejuror.ui.client.service.PersonViewServiceAsync;
import com.xerox.tclg.ejuror.ui.client.workbench.StyleHelper;

/**
 * Form for uploading images to the main server
 * @author Xerox Services
 */
public class UploadForm extends MessageEnabledContainer {
  //instance variables
  private String                  description;
  private String                  cancel;
  private String                  file;
  private MessageResource         messageResource;
  private String                  ok;
  private PersonViewServiceAsync  personViewService = (PersonViewServiceAsync) GWT.create(PersonViewService.class);

  //UI components
  private Button                  btnOk;
  private Button                  btnCancel;
  private ButtonBar               buttonBar;
  private LabelField              lblTitle;
  private FormPanel               form;
  private LayoutContainer         header;
  private LayoutContainer         layMain;
  private TextField<String>       textDescription;
  private FileUploadField         uploadFile;

    /**
   * Create a disclaimer page that will show disclaimers and return the results in a callback
     * @param icon
     * @param header1
     * @param header2
     * @param disclaimerText
     * @param buttonFlags
     */
    public UploadForm() {
    String    selectFile;
    String    title;
    messageResource = ImageViewer.getImageViewer();
    if(isDesignTime()){
      cancel = "Cancel";
      description = "Short Description<BR/>(e.g. Doctor's Letter)";
      file = "File";
      ok = "Ok";
      selectFile = "Select a File to Upload";
      title = "Upload a File";
    }
    else{
      cancel = messageResource.getString(Messages.MSGKEY_CANCEL);
      description = "Short Description<BR/>(e.g. Doctor's Letter)";
      file = "File";
      ok = messageResource.getString(Messages.MSGKEY_OK);
      selectFile = "Select a File to Upload";
      title = "Upload a File";
    }

    addStyleName("white-screen");
    setWidth(MainLayout.FORM_WIDTH);  
        setLayout(new TableLayout());

        header = new LayoutContainer();
        TableLayout tl_header = new TableLayout(2);
        tl_header.setCellSpacing(5);
        header.setLayout(tl_header);

    Image imageUpload = new Image(EjurorBundle.BUNDLE.uploadIcon());
    header.add(imageUpload);

    String str = StyleHelper.formatHeader(title);
    lblTitle = new LabelField(str);
    header.add(lblTitle);

    layMain = new LayoutContainer();
    TableLayout tl_layMain = new TableLayout();
    tl_layMain.setCellPadding(5);
    layMain.setLayout(tl_layMain);

    layMain.add(header);

    form = new FormPanel();
    form.setHeading(selectFile);  
    layMain.add(form);

    buildUploadForm();

    buildButtonBar();

    FooterContainer footer = new FooterContainer("50");
    TableData td_footer = new TableData();
    td_footer.setWidth("100%");
    layMain.add(footer, td_footer);
    footer.setSize("740", "");

    add(layMain);

    loadUrl();
    }

  /**
   * 
   */
  private void buildButtonBar() {
//    buttonBar = new ButtonBar();
//    buttonBar.setAlignment(HorizontalAlignment.RIGHT);
//    buttonBar.setHeight(MainLayout.BUTTON_BAR_HEIGHT);
//    form.add(buttonBar);

    btnOk = new Button(ok);
    btnOk.setSize(MainLayout.BUTTON_WIDTH, MainLayout.BUTTON_HEIGHT);
    btnOk.addSelectionListener(new SelectionListener<ButtonEvent>() {
      @Override
      public void componentSelected(ButtonEvent be) {
        if(form.isValid()){
          upload();
        }
        else{
          MessageBox.info("Validation Error", "You must enter all required fields.", null);
        }
      }
    });
//    buttonBar.add(btnOk);
    form.add(btnOk);

    btnCancel = new Button(cancel);
    btnCancel.setSize(MainLayout.BUTTON_WIDTH, MainLayout.BUTTON_HEIGHT);
    btnCancel.addSelectionListener(new SelectionListener<ButtonEvent>() {
      @Override
      public void componentSelected(ButtonEvent be) {
        exit();
      }
    });
//    buttonBar.add(btnCancel);
    form.add(btnCancel);
    }

  /**
   * 
   */
  private void buildUploadForm() {
    form.setFrame(true);  
    form.setEncoding(Encoding.MULTIPART);  
    form.setMethod(Method.POST);  
    form.setButtonAlign(HorizontalAlignment.CENTER);  
    form.setWidth(MainLayout.CONTENT_WIDTH);  
    form.addListener(Events.Submit, new Listener<FormEvent>() {
      public void handleEvent(FormEvent fe) {
        System.out.println(fe.getResultHtml());
      };
    });  

    String desc = StyleHelper.formatPrompt(description);
    textDescription = new TextField<String>();
    textDescription.setAllowBlank(false);
    textDescription.setFieldLabel(desc);
    form.add(textDescription);

    String fileLabel = StyleHelper.formatPrompt(file);

    uploadFile = new FileUploadField();
    uploadFile.setAllowBlank(false);
    uploadFile.setFieldLabel(fileLabel);
    form.add(uploadFile);
  }

  /**
   * Jump back to the landing page
   */
  protected void exit(){
    ImageViewer.getImageViewer().showLanding();
  }

  /**
   * 
   */
  protected void upload(){
    form.submit();
    exit();
  }

  /**
   * Load the URL from the person service
   */
  private void loadUrl() {
    personViewService.buildUploadUrl(new AsyncCallback<String>() {

      @Override
      public void onFailure(Throwable caught) {
        System.err.println("Unable to construct URL");
        caught.printStackTrace();
        MainLayout.showError(caught.getMessage());
      }

      @Override
      public void onSuccess(String url) {
        form.setAction(url);
      }
    });
  }

  /**
   * GWT-Designer will change to return true during design time
   * 
   * @return
   */
  private static final boolean isDesignTime() {
    return false;
  }
}

ご覧のとおり、URL は動的に構築されます。

問題は、これを実行して [OK] ボタンをクリックしても、サーブレットが呼び出されないことです。レンダリングされた HTML を見て、アクション内の URL をコピーしてブラウザに貼り付けると、サーブレットが呼び出されるので、URL は問題ありません。

submit が呼び出されていることも確認しました。

誰かが私を正しい方向に向けることができますか? 私はこの例に従っています:

http://extjs-public.googlecode.com/svn/gxt/release/samples/examples/www/com.extjs.gxt.samples.Examples/forms/fileupload.html

4

2 に答える 2

0

これを試して (またはデバッグして)、アップロードが呼び出されるかどうかを確認してください。おそらくあなたのフォームは有効ではありません:

//if(form.isValid()){
          upload();
  //      }
于 2013-07-03T08:25:37.047 に答える