Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Set maxFileSize validator in data source descriptor (ds.xml file)

    Hi Isomorphic. I have a binary field for which I want to add two validations, one for a maximum size and the other to avoid the file upload to start when no file has been selected. Here is my code:

    Code:
    <field name="bankfile" type="binary" maxFileSize="20971520">
        <title><fmt:message key="bankload_loadFile"/></title>
        <validators>
            <validator type="maxFileSize">
                <errorMessage><fmt:message key="bankload_fileSizeInvalid"/></errorMessage>
            </validator>
            <validator type="required">
                <errorMessage><fmt:message key="bankload_noFileSelected"/></errorMessage>
            </validator>
        </validators>
    </field>
    But it won't allow me to process any files, not even 2KB files. I guess the problem must be related to setting the validator value for the maxFileSize (although the docs here say that the validations will be made against the DataSourceField.maxFileSize, which I have defined properly (I think).

    I tried removing the "required" validator, but it didn't work either. Removing the "maxFileSize" validator results in the "required" validator working correctly, and also the "maxFileSize" being imposed properly, but the error message for the maximum file size is (as expected) not displayed in the proper user locale.

    Can you please help me with this validation?

    Thanks

    #2
    Please be specific about what's going wrong - with the explicit maxFileSize validator in place, are you seeing a failure to submit the file at all, a problem during server side processing, an error message but not one you were expecting, or what? Make sure to include the server-side log if the request reached the server at all.

    Comment


      #3
      Hi Isomorphic. Sorry, I realize I wasn't clear. When I leave the "maxFileSize" validator, the file fails to submit. Here is the message when I leave the two validators shown above. In this case the message is localized using my resource bundle labels correctly, but it is being presented even for very small files (way smaller than the 20MB limit), so no files can be submitted at all.

      Click image for larger version

Name:	LoadSmallFilesFails.png
Views:	187
Size:	9.5 KB
ID:	237822

      Removing the "maxFileSize" validator allows proper small file (20MB or less) submission and processing, but when a big file is chosen, the validation message is not the one in my resource bundle (but a non-localized standard SmartGWT message):

      Click image for larger version

Name:	NotLocalizedValidationError.png
Views:	204
Size:	11.8 KB
ID:	237823

      By the way, it's SmartGWT 6.0p 2016-04-12. Thanks!

      Comment


        #4
        Hi Isomorphic. I would really appreciate any further guidance on this issue, since I've tried looking everywhere, and it would seem that my validators are defined properly. Am I missing something here?
        Thanks

        Comment


          #5
          Well, after much digging, I found out that validators are not supported for binary fields.

          Isomorphic, a possible improvement to the docs could be to say this explicitly here, at the end ot the Restricting upload sizes sub-section, where you also talk about the maxFileSize validator that gets added automatically. And you could also mention it here.

          IMHO, the information is there, but it certainly is not easy to find as it is.

          Follow up question (or suggestion for improvement): is there any way to add a localized message to the maxFileSize validator you automatically add when the DataSourceField has the maxFileSize property set to some value? This would allow for a more homogeneous UX (because right now we can set all messages to be localized, except for this one).

          Comment


            #6
            Thank you for your effort, we are working on this.

            Comment


              #7
              Thanks Isomorphic. That's great to hear...

              Comment


                #8
                Hi Isomorphic. Have you been able to make any progress on this? (I hope it's not too low in your priority queue :) )
                Thanks

                Comment


                  #9
                  Sorry for the delay and thank you for your patience. This is fixed now and will be available for download in nightly builds since June 14 (tomorrow).

                  You will need to remove maxFileSize validator from your ds.xml. To customize error message you need to use DataSource.maxFileSizeExceededMessage property (see updated docs for maxFileSize validator). As for required validator, leave it in your ds.xml as you showed us in your post.

                  Comment


                    #10
                    Thanks Isomorphic!! I will try this when the version is available and let you know how it goes.

                    Comment


                      #11
                      Hi Isomorphic. I am testing this, and indeed I can provide now a custom error message for the maxFileSize validation, but I can't seem to be able to localize this message. Here is what I got so far:

                      Code:
                      <?xml version="1.0" encoding="utf-8"?>
                      <DataSource
                          xmlns="focuss/ds"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xsi:schemaLocation="focuss/ds ds.xsd"
                              
                          ID="bank_load"
                          serverType="sql"
                          tableName="bank_load"
                          xmlns:fmt="focuss/fmt"
                          [B]maxFileSizeExceededMessage="The file size exceeds the maximum allowed!"[/B]>    
                      
                          <fmt:bundle basename="co.focuss.bmsim.shared.i18n.BMSimResources" encoding="utf-8"/>
                          
                          <fields>
                              
                              <field name="id" type="sequence" hidden="true" primaryKey="true"/>  
                              
                              <field name="bankfile" type="binary" maxFileSize="2097152">
                                  <title><fmt:message key="bankload_loadFile"/></title>
                                  <validators>
                                      <validator type="required">
                                          <errorMessage><fmt:message key="bankload_noFileSelected"/></errorMessage>
                                      </validator>
                                  </validators>
                              </field>
                      
                          </fields>
                      </DataSource>
                      Is this intended to be localized as well?

                      If so, can you point to any documents or resources showing this? I couldn't find any references to the maxFileSizeExceededMessage property here or here, which I expected to find because of what is said here and here (and also what you say in your last post). Also, in these two latter links the new property is only mentioned, but nothing is said about the usage regarding localization use case, which is the main need here.

                      Thanks

                      Comment


                        #12
                        It works like any other tag in a .ds.xml. Take maxFileSizeExceededMessage and make it a subelement instead of an attribute, then use a <fmt:message> tag inside it as usual.

                        Comment


                          #13
                          Thanks once again for your response. I tried that also, but when I do it, the validator simply stops working (no error message -custom or native- is shown). Here is the code:

                          Code:
                          <?xml version="1.0" encoding="utf-8"?>
                          <DataSource 
                              xmlns="focuss/ds"
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:schemaLocation="focuss/ds ds.xsd"
                                  
                              ID="bank_load" 
                              serverType="sql" 
                              tableName="bank_load" 
                              xmlns:fmt="focuss/fmt">    
                          
                              <fmt:bundle basename="co.focuss.bmsim.shared.i18n.BMSimResources" encoding="utf-8"/>
                              
                          [B]    <maxFileSizeExceededMessage>
                                  <fmt:message key="bankload_fileSizeInvalid"/>
                              </maxFileSizeExceededMessage>[/B]
                              
                              <fields>
                                  
                                  <field name="id" type="sequence" hidden="true" primaryKey="true"/>  
                                   
                                  <field name="bankfile" type="binary" maxFileSize="20971520">
                                      <title><fmt:message key="bankload_loadFile"/></title>
                                      <validators>
                                          <validator type="required">
                                              <errorMessage><fmt:message key="bankload_noFileSelected"/></errorMessage>
                                          </validator>
                                      </validators>
                                  </field>
                                          
                              </fields>
                          </DataSource>
                          Thanks for bearing with me here!

                          Comment


                            #14
                            No problem. This is fixed now and will be available for download in nightly builds since June 17 (tomorrow).

                            Comment


                              #15
                              Thanks Isomorphic. I'll test it again tomorrow!!

                              Comment

                              Working...
                              X