创建包含附件的Notes文档,为什么必须执行完全刷新才能保存它?

时间:2018-11-25 19:12:17

标签: java xpages

在我的XPages应用程序中,我通过xe:dialog控件显示“表单”。表单仅包含xp:fileUpload控件作为输入。

<xp:fileUpload id="ctrlUpload"
    value="#{attachmentBean.uploadedFile}"
    disabled="#{javascript:!compositeData.editable}"
    disableValidators="true">
    <xp:this.attrs>
        <xp:attr name="data-duplicate"
            value="#{matter.attachment_duplicate_warning}" />
        <xp:attr name="data-limit"
            value="#{matter.attachment_file_limit}" />
        <xp:attr name="data-error"
            value="#{matter.attachment_limit_exceed}" />
        <xp:attr name="data-show-preview"
            value="false" />
    </xp:this.attrs>
    <xp:eventHandler event="onchange"
        submit="false">
        <xp:this.script>
            <xp:executeClientScript>
                <xp:this.script><![CDATA[function x$(idTag, param){
idTag=idTag.replace(/:/gi, "\\:")+(param ? param : "");
return($("#"+idTag));
}

//get the file that the user has selected
var fileToBeUploaded = document.getElementById("#{id:ctrlUpload}").value;
var test = '#{javascript:getComponent("ctrlUpload").size}';

var dots = fileToBeUploaded.split(".")
var fileType = dots[dots.length - 1];
//grab the file extension to see if it's approved to be attached to the proposal
fileType = fileType.toLowerCase();

//get the list of approved file extensions - is calculated in a computed field
var computedField = XSP.getElementById("#{id:lu_approvedFileExtensions}");
var listOfApprovedFileExtensions = computedField.innerHTML;

//check if the selected extension is in the approved list
var extensionIsInList = listOfApprovedFileExtensions.indexOf(fileType);
if (extensionIsInList == -1) {
//the selected file extension is not in the list of approved extensions.

alert(listOfApprovedFileExtensions);
XSP.getElementById("#{id:ctrlUpload}").value = "";
x$("#{id:btnSaveFile}").attr('disabled', 'disabled');
return false;
} else {
x$("#{id:btnSaveFile}").attr('disabled', false);
}]]></xp:this.script>
            </xp:executeClientScript>
        </xp:this.script>
    </xp:eventHandler>
</xp:fileUpload>

数据是通过使用按钮触发的后端类提交的:

<xp:button value="#{matter.attachment_upload}"
    id="btnSaveFile" styleClass="btnSaveFile" disabled="true">
    <i class="fa fa-upload" aria-hidden="true" />
    &#160;
    <xp:eventHandler event="onclick"
        submit="true" refreshMode="complete" execMode="partial"
        execId="pnlFilesBS" disableValidators="true"
        onComplete="$('#myModal').modal('show');">
        <xp:this.action><![CDATA[#{javascript:attachmentBean.save(viewScope.get("principalUnid"),viewScope.get("principalUnid"));
var ref = viewScope.get("principalUnid")
var key = viewScope.get("principalUnid")
attachmentBean.loadList(ref, key);
viewScope.put("attachments" + ref + key, attachmentBean.getAttachments());
facesContext.getViewRoot().postScript("$('#myModal').modal('show');");}]]></xp:this.action>

    </xp:eventHandler>
</xp:button>

我的java类中的save方法是紧随其后的:

public void save(String parentId, String type) throws NotesException {
    try {
        if (null != uploadedFile) {
            Database db = utils.openDatabase(server, dbPath + dbName);
            if (null != db){
                IUploadedFile iUploadedFile = uploadedFile.getUploadedFile();
                String tempClientFile = iUploadedFile.getClientFileName();
                File tempFile = iUploadedFile.getServerFile();
                String filePath = tempFile.getAbsolutePath();
                File correctedFile = new File(tempFile.getParentFile() + File.separator + tempClientFile);
                tempFile.renameTo(correctedFile);
                boolean success = true;
                if (success) {
                    Document doc = db.createDocument();
                    doc.appendItemValue("Form","fa_Attachment");
                    doc.appendItemValue("parentId", parentId);
                    doc.appendItemValue("type", type);

                    Name origAuthor = utils.getSession().createName(utils.getSession().getEffectiveUserName());

                    Vector<String> vecAuthors = new Vector<String>(4);
                    vecAuthors.add("[Admin]");
                    vecAuthors.add("[SuperAdmin]");
                    vecAuthors.add("[SuperDuper]");
                    vecAuthors.add(origAuthor.getCanonical());

                    TreeSet<String> uniqueAuthors = new TreeSet<String>(vecAuthors);
                    vecAuthors = new Vector<String>(uniqueAuthors);

                    Item authorRole = doc.replaceItemValue("Authors", vecAuthors);
                    authorRole.setAuthors(true);

                    RichTextItem rtFiles = doc.createRichTextItem("files");               
                    rtFiles.embedObject(lotus.domino.EmbeddedObject.EMBED_ATTACHMENT, "", correctedFile.getAbsolutePath(), null);

                    doc.save();

                    MultiGrowlMessages growl = new MultiGrowlMessages();
                    growl.createGrowlMessage("File: " + iUploadedFile.getClientFileName() + " uploaded", "success");

                    rtFiles.recycle();
                    doc.recycle();

                    correctedFile.renameTo(tempFile);

                    uploadedFile = null;
                }               
            }        
        }else{
              MultiGrowlMessages growl = new MultiGrowlMessages();
                growl.createGrowlMessage("you did not select a file", "error");
        }
    } catch (Exception e) {
        OpenLogUtil.logError(e);
    }
 }

此代码运行良好,但我必须将refreshMode属性设置为完整。否则,似乎没有任何数据可以提交。

当然,在完全提交状态下,该对话框将被关闭,这是不必要的,因为在同一对话框中,我显示了其他具有相同引用的上载文件,当然,我希望此列表(xp:repeat控件)仅用于进行更新,以便新添加的上传文档将包含在此列表中。

有人知道我在做什么错吗?我在表单上有多个上载控件,使用在对话框中显示的相同自定义控件在不同条件(引用)下上载文件。

0 个答案:

没有答案