簡體   English   中英

XPages CSJS被執行而SSJS不被執行

[英]XPages CSJS gets executed while SSJS does not

我有一個用於將文件上傳到頁面的自定義控件。 它工作得很好,但是只有當它不在xp.this.rendered屬性中時才起作用 如果是這樣,它將給我帶來非常意外的結果。 這是我使用的div的代碼:

        <div style="height:0px;overflow:hidden">
            <input type="file"
                id="${javascript:compositeData.ID+'_files_input'}"
                onchange="#{javascript:
      var currentCustomID = compositeData.ID; 

      var filesInput = '\'' + currentCustomID + '_files_input' + '\'';
      var filesUpload = '\'' + currentCustomID + '_files_upload' + '\'';
      var filesButton = '\'' +  currentCustomID + '_files_button' + '\'';
      var filesProgress = '\'' +  currentCustomID + '_files_progress' + '\'';

      return 'files_onchange(' + filesInput + ',' + filesUpload + ',' + filesButton + ',' + filesProgress + ')';
      }"
                multiple="true" uploadOnSelect="true" name="uploadedfile" />

            <xp:fileUpload
                id="${javascript:compositeData.ID+'_files_upload'}"
                useUploadname="true">
                <xp:this.value><![CDATA[#{doc_source[compositeData.FieldName]}]]></xp:this.value>
            </xp:fileUpload>

<xp:button value="Refresh"
        id="${javascript:compositeData.ID+'_files_button'}">
        <xp:eventHandler event="onclick" submit="true"
          refreshMode="partial"
          refreshId="${javascript:compositeData.ID+'refresh'}"
          disableValidators="true">
          <xp:this.action>


            <xp:actionGroup>
              <xp:actionGroup>

              <xp:executeScript
                script="#{javascript:print('But server side executes only without RENDERED')}">
              </xp:executeScript>

                <xp:saveDocument></xp:saveDocument>
                <xp:executeScript>
                  <xp:this.script><![CDATA[#{javascript:
if (compositeData.postUpload!=null)
{
compositeData.postUpload.getScript().invoke(facesContext, null)
}
//print("сука");
}]]></xp:this.script>
                </xp:executeScript>
              </xp:actionGroup>

            </xp:actionGroup>
          </xp:this.action>

          <xp:this.script>
            <xp:executeClientScript
              script="console.log('CSJS works so well')">
            </xp:executeClientScript>
          </xp:this.script>
          </xp:eventHandler>
      </xp:button>
        </div>

上面的代碼中有一個刷新按鈕,該按鈕應該是saveDocument,以便文檔保存剛收到的文件。

另外,有一些代碼發送帶有表單數據的XHR請求:

function files_onchange(filesInput, filesUpload, filesButton, filesProgress) 
{
    var urfiles = document.getElementById(filesInput).files;
    files_upload(filesInput, filesUpload, urfiles, 0, filesButton, filesProgress);
}           

function files_upload(filesInput, uploadID, files, counter, refreshID, filesProgress)
{

    var url = window.location.href;

    var formData = new FormData();
    var file = null;
    var form = XSP.findForm(filesInput);
    if (!files) return;
    var numberOfFiles = files.length;
    file = files[counter];
    var max = files.length;
    if (counter >= max) return;

    formData.append(document.querySelector('[id$=' + uploadID + ']').id, file);
    formData.append("$$viewid", dojo.query("input[name='$$viewid']")[0].value);
    formData.append("$$xspsubmitid", dojo.query("input[name='$$xspsubmitid']")[0].value);
    formData.append("$$xspsubmitvalue", dojo.query("input[name='$$xspsubmitvalue']")[0].value);
    formData.append("$$xspsubmitscroll", dojo.query("input[name='$$xspsubmitscroll']")[0].value);
    formData.append(form.id, form.id);


    var xhr = new XMLHttpRequest();


    /* event listners */

      xhr.upload.addEventListener("progress", function(e) 
      {
          if (e.lengthComputable)

           {
                var percentComplete = Math.round(e.loaded * 100 / e.total);
                document.getElementById(filesProgress).innerHTML = percentComplete.toString()+'%, ( '+(counter+1).toString()+' / '+numberOfFiles.toString()+' )';
           }
              else 
              {
                document.getElementById(filesProgress).innerHTML = '...';
              } 
      }, false);


      xhr.addEventListener("load", function()
      {
          counter++; 
          if (counter >= max)
          {
              document.getElementById(filesInput).value = "";

              if (refreshID) 

              {
                  document.querySelector('[id$=' + refreshID + ']').click(); // it's supposed to trigger the refresh button
              }

          } 
        else 
              { 
                files_upload(filesInput, uploadID, files, counter, refreshID, filesProgress) 
              }

      }, false);

     xhr.addEventListener("error", function(e) 
     {
         document.getElementById(filesProgress).innerHTML = "Error: "+e;

     }, false);

     xhr.addEventListener("abort", function()
     {
         document.getElementById(filesProgress).innerHTML = "Upload cancelled.";

     }, false);

      xhr.open("POST", url, true);
      xhr.send(formData);
      document.querySelector('[id$=' + uploadID + ']').value = '';
}

我不知道為什么document.querySelector('[id$=' + refreshID + ']').click()中的CSJS代碼總是會被執行。 不管xp.this.rendered屬性如何,我總是在瀏覽器控制台中打印出'CSJS works so well' ,而But server side executes only without RENDERED ,而沒有呈現屬性(或者如果將其永久設置為真正)。 背后的原因是什么? 提前致謝。

確保“顯示錯誤”組件在刷新區域中,並檢查驗證錯誤。 這是CSJS運行但SSJS沒有運行的最常見原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM