0
createContent : function(oController) {

        var oFileUploader  = new sap.ui.commons.FileUploader({
            id: "FileULoader",
        //uploadUrl : "UploadFileServelet",   // URL to submit the form to
        name: "simpleUploader",          // name of the input type=file element within the form 
    //  uploadOnChange: true,           // immediately upload the file after selection
        buttonOnly: false,
        buttonText: "Upload"
        }).addStyleClass("downloadBtn");
        oFileUploader.attachUploadComplete(oController.doFileLoadComplete);  
    //var uploadBtn=new sap.ui.commons.buttons{this.creatId("upLoadFile"),}



    var oMatrix = new sap.ui.commons.layout.MatrixLayout({
        layoutFixed : true,
        width : '400px',
        columns : 1 });

    var text = new sap.ui.commons.TextView({text:"Confirm that the data will be wiped out once you upload new data file."});

    oMatrix.createRow(oFileUploader);
    oMatrix.createRow(text);

    var oDialog = new sap.ui.commons.Dialog({
        title:"FileUpload",
        resizable:false,
        modal:true,
        showCloseButton:true,
        contentBorderDesign:"Box",
        content:[
                 oMatrix   
        ],
        buttons:[
            new sap.ui.commons.Button({text:"Confirm", tooltip:"Confirm",press:function(e){oController.doFileUpload();oDialog.close();}}),
            new sap.ui.commons.Button({text:"Cancel", tooltip:"Cancle",press:function(e){oDialog.close();}}),
        ]
    });
    return oDialog;

i used in two views . when i call the fileUploader the error turns out。 i have to use the id to identify the fileloder controller. to get the input file information .

update:

_uploadCourse:function(){
    if (!this.dialogUploadFile) {
        this.dialogUploadFile = sap.ui.jsfragment("courseUP",
                "adminView.dialogUploadFile", this);
    }
    this.dialogUploadFile.open();
},
_uploadCourse : function() {

                    if (!this.dialogUploadFile) {
                        this.dialogUploadFile = sap.ui.jsfragment("certiUploadFile",
                                "adminView.dialogUploadFile", this);
                    }
                    this.dialogUploadFile.open();
                },

this is how i use the fragment. but is still go wrong with thew same error; @Allen Zhang

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
islandev
  • 33
  • 5

2 Answers2

0

You mentioned you used the code in two views. You can't create a dialog twice with the same id of Fileupload control. Use different id for different views.

Updated:

Define id for your fragment usage:

<core:Fragment id="myFrag" fragmentName='my.frag' type='JS' />

Define fileupload id by calling createId:

var oFileUploader  = new sap.ui.commons.FileUploader({
        id: this.createId("FileULoader"),
    //uploadUrl : "UploadFileServelet",   // URL to submit the form to
    name: "simpleUploader",     // name of the input type=file element within the form 
//  uploadOnChange: true,           // immediately upload the file after selection
    buttonOnly: false,
    buttonText: "Upload"
    }).addStyleClass("downloadBtn");

Also see my answers about fragment usage and get control inside fragment.

Community
  • 1
  • 1
Haojie
  • 5,665
  • 1
  • 15
  • 14
  • i try this, but it didn't work. so i creat another fragments to do it. i wonder is there any method to get the control not by id. but by type or something else? – islandev Aug 26 '14 at 02:05
  • could you please elaborate your requirement? The same fragment is used by multiple views and you need to get the uploader control? – Haojie Aug 26 '14 at 02:29
  • but when it has an id. the dupiulicate id error exit. so my question is : is there anyway to get an controller that it has no id? BTW: is there any solution to make the fragments to Singleton? thanks in advance. – islandev Aug 26 '14 at 03:06
  • Hi, give fragment an id when you use and let the uploader id be this.createId("FileULoader"), this method will generate fragment id prefixed id for uploader. – Haojie Aug 26 '14 at 03:27
  • Unfortunately the question was put on hold so I can´t post an answer but to use the fragment as a singleton you can do it the same way as described [here](http://stackoverflow.com/a/24278751/1969374). – Tim Gerlach Aug 26 '14 at 07:02
  • hi, you need to maintain two different instances of dialog fragment.See this example i did in JSbin http://jsbin.com/kahaxo/2/edit – Haojie Aug 26 '14 at 08:00
0

Is an option that you do not use id for the file uploader control, and do it like this?

createContent : function(oController) {
    this.oFileUploader = new sap.ui.commons.FileUploader({

To access it, you do

view.oFileUploader

where view is the javascript handle of one of your two views.

-D

D. Seah
  • 4,472
  • 1
  • 12
  • 20