Tuesday, 21 June 2011

Wicket Ajax Callback and FileUploadField

NextReports Server has an Upload action for different kind of reports.  Besides selecting report files and images, user has to enter a name for the report. We wanted to automatically set the name after selecting file (for lazy people), but this approach proved to be incorrect.

We had something like in the following snippet:
uploadField.add(new AjaxEventBehavior("onchange") {
              
     protected void onEvent(AjaxRequestTarget target) {
         Request request = RequestCycle.get().getRequest();
         String filename = request.getParameter("filename");
         String text = getModel().getObject().getName();
         if ((text == null) || "".equals(text.trim())) {
            int index = filename.lastIndexOf(".");
            if (index > 0) {
               filename = filename.substring(0,  index);
            }
            getModel().getObject().setName(filename);                       
         }                   
         target.addComponent(name);
     }

     public CharSequence getCallbackUrl(boolean onlyTargetActivePage) {
         CharSequence callBackUrl = super.getCallbackUrl(onlyTargetActivePage);
         return callBackUrl + "&filename=' + this.value + '";
     }

});

Starting from IE8 and also in Chrome, but not yet in Firefox,  according to the specifications of HTML5, a file upload control should not reveal the real local path to the file you have selected, if you manipulate its value string with JavaScript. Instead, the string that is returned by the script, which handles the file information is c:\fakepath.

So, we have to give up using this functionality.

1 comment:

  1. IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes. IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble.Final Year Projects for CSE

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining .

    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    The Angular Training covers a wide range of topics including Angular Directives, Angular Services, and Angular programmability.Angular Training

    ReplyDelete