-2

I'm trying to upload a file and send it to a java servlet using post method. My dojo is 1.8. Just started working with javascript and still have tons to learn. Please correct me if you can. So i have a couple of undefined attributes: label, UploaderID and dojo source path which is supposed to be true!

   **************** REVISED CODE ***************************

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>dojox.form.Uploader</title>

    <link href="dijit/themes/dijit.css" rel="stylesheet" />
    <link href="dijit/themes/claro/Common.css" rel="stylesheet" />
    <link href="dijit/themes/claro/form/Common.css" rel="stylesheet" />
    <link href="dijit/themes/claro/form/Button.css" rel="stylesheet" />
    <link href="dojox/form/resources/UploaderFileList.css" rel="stylesheet" />

     <script type="text/javascript" 
      src="//ajax.googleapis.com/ajax/libs/dojo/1.8/dojo/dojo.js" 
     data-dojo-config="parseOnLoad: true, async: true, 
                                         isDebug: true, 
                                         packages: [{name: 'dojo', location: '.'},
                                                    {name: 'dijit', location: 
                                                     '/dojo/dijit'},
                                                    {name: 'dojox', location:
                                                       '/dojo/dojox'},
                                                     ]"></script>

    <script> 
      dojo.require("dojo.domReady")
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");
dojo.require("dijit.form.TextBox");   
dojo.require("dojox.form.Uploader");
dojo.require("dojox.form.uploader.FileList");
dojo.require("dojo.parser");
});
    </script> 
</head>
<body class="claro">
    <form method="post" action="user" id="myForm" enctype="multipart/form-data" >
        <fieldset style="background-color:lightblue;">

            <h1 id="greeting">User Administration</h1>

    <p>First Name: <input type="text" name="fname" size="20"> 

            LastName: <input type="text" name="lname" size="20"></p>    

            <input class="browseButton" name="uploadedfile" multiple="false"   
            type="file" data-dojo-type="dojox.form.Uploader" label="Select Some File"
           id="uploader" />

           <p><input type="submit" label="Submit" data-dojo-type="dijit.form.Button" />
            </p>

           <div id="files" data-dojo-type="dojox.form.uploader.FileList"
            uploaderId="uploader"></div>
        </fieldset>
    </form>                     
</body>
</html>
user3655096
  • 57
  • 1
  • 2
  • 8
  • Thanks Dimitri, I corrected all the necessary changes. However, I think my problem is that my modules aren't being recognized. I imported the release version of dojo 1.8 to my WebContent file as a file system in my eclipse. Instead of label: Select Some File. I'm getting Browse. – user3655096 Jun 12 '14 at 14:17

2 Answers2

0

I'm noticing several errors here:

First line in your <script>:

dojo.required("dojo.domready")

dojo.required() does not exist and should be dojo.require().

Besides that, dojo.domready is not even a module and should be dojo.domReady


The following code is just wrong:

function(parser){
    parser.parse();
});

You probably copy pasted it from a code example that was using AMD, however, you're no longer using AMD (but dojo.require()), so this code won't even compile.

However, you're using the parseOnLoad mechanism, so in fact you don't need to parse the page by yourself (this will even cause errors because you're going to parse the same widgets twice).

Remove that part of the code, all you need to make the parse on load mechanism to work is:

dojo.require("dojo.parser");

This code looks like some failed try to convert an AMD example to non-AMD code, another thing you're doing wrong is:

dojo.require("dijit.form/Button");

You should use the dot notation when usin pre-AMD code (dijit.form.Button). Dojo will probably understand this, at least it will in the recent Dojo versions, but I doubt that this will work in older versions of Dojo.


You're splitting attribute names by a newline, for example:

<input class="browseButton" name="uploadedfile" multiple="false" type="file" data-
    dojo-type="dojox.form.Uploader"
    label="Select Some File" id="uploader" />

The attribute name data-dojo-type should probably be one 1 line, I don't think it's valid if you split that attribute onto multiple lines.


The Dojo configuration property to parse the page when it's loaded is parseOnLoad (not ParseOnLoad). I'm not sure if Dojo handles these properties case insensitive, but normally JavaScript properties are case sensitive.

However, you're already using the data-dojo-config property on your <script> tag loading Dojo, so you actually don't even need that.


If you fix all these errors your script should work fine (with or without AMD), as you can see in this fiddle: http://jsfiddle.net/e65EY/

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
-1

Have set up the dojo.js correctly? How are you using your application? Have you downloaded the dojo source files in your machine or using some remote server. You can use the google CDN as show below. Also have look over here of setting your dojo source.

src="//ajax.googleapis.com/ajax/libs/dojo/1.8/dojo/dojo.js"

In addition to @Dmitri comments.
Remove the below line.

<script> dojoConfig ={isDebug:true, ParseOnLoad: true,};</script>

because you are redefining the dojoConfig in the very next line via. data-dojo-config

<script type="text/javascript" src="dojo/dojo.js" 
        data-dojo-config="async: true,isDebug: true,parseOnLoad: true"></script>

Also you can use the new AMD format for require() call as below.

<script type="text/javascript"> 
require([
            "dojo/parser",
            "dijit/form/Button",
            "dijit/Dialog",
            "dijit/form/TextBox",
            "dojox/form/Uploader",
            "dojox/form/uploader/FileList"
            "dojo/domReady!"
], function (parser, Button, Dialog, TextBox, Uploader, FileList ) {
// now parse the page for widgets
            parser.parse();
// Your code will go here
});
</script>
frank
  • 3,180
  • 3
  • 16
  • 18
  • I added the src to my WebContent file(eclipse). Not sure if it's being read. This is my index.html of a java servlte that will read the names and read the uploaded file. Still getting the attributes not being recognized : lable and uploaderId – user3655096 Jun 12 '14 at 14:27