0 Replies Latest reply on Oct 13, 2010 9:34 AM by atyauristen

    Fileupload + ajax

    atyauristen

      hey there everybody,

       

      i have a question regarding a form with an inputfileupload (tomahawk) and some other elements, such as a textarea input.

       

      what i wanna do is to check whether the input area is filled and if so, i do the upload of the file also.

      the problem for me is to do this the ajaxian way, so to make the check i don't wanna do a page refresh, but the 'usual' way with ajax rerender.

      the tricky thing is that if the input file upload is not set, i want to post the content of the area with ajax, actually i would like to upload the file ajax way as well, but as far as i know it's not possible.

       

      so what i did is i have an a4j commandlink to make the validation and oncomplete if the validation does not fail, i fire either a hidden h:commandlink or an a4j:jsfunction without fileupload.

       

      the problem is that i have some protections on my button not to allow to click it until the request is done. it looks like this:

       

      <a4j:commandButton
      id="ajaxButton"
      status="wallContentAdderStatusPic"
      actionListener="#{wallAction.validateWallInput}"
      styleClass="normalButton pinInOn ajaxButton"
      value="#{labels.wallPinItOn}"
      reRender="wallContents"
      ignoreDupResponses="true"
      eventsQueue="wallEventQ"
      onclick="disableOnClick(this);"
      ondblclick="disableOnClick(this);"
      oncomplete="enableOnComplete(this);
      if(#{facesContext.maximumSeverity != 'Error'}){
      if(wallFormHasAttachment){
      jQuery('.uploadSubmitter').click();
      }else{
      submitNormal();
      }
      }else{
      }">
      </a4j:commandButton>

      <a4j:commandButton

      id="ajaxButton"

      status="myStatus"

      actionListener="#{action.validateWallInput}"

      styleClass="normalButton ajaxButton"

      value="#{labels.post}"

      reRender="contents"

      ignoreDupResponses="true"

      eventsQueue="wallEventQ"

      onclick="disableOnClick(this);"

      ondblclick="disableOnClick(this);"

      oncomplete="enableOnComplete(this);

      if(#{facesContext.maximumSeverity != 'Error'}){

      if(wallFormHasAttachment){

      jQuery('.uploadSubmitter').click();

      }else{

      submitNormal();

      }

      }else{

      ....

      }">

      </a4j:commandButton>

       

      but if i do not rerender this a4j button, i cannot click it again. however, i cannot rerender itself because in that case it wont wait for the oncomplete request to finish. if i put the rerender on the submitNormal() js function, it's okay, but then it's called only if there was no error, so with an error (that's the 'else' branch) it wont reenable the original button.

       

      i might overcomplicate things, but i just could not find a proper solution.

       

      so if you have any suggestions, don't hesitate to answer, any help is appreciated!

       

      cheers,

      b