XPages - 发生部分刷新时View不会更新

时间:2013-09-04 10:29:02

标签: xpages lotus-notes page-refresh

我有一个绑定到doc数据源的页面。页面顶部是一个面板,其中设置了doc的字段。在页面底部是文档视图。

假设字段是[A]和[B],[B]的值取决于[A],它在某些值变化时部分刷新[B]。当我只设置不触发部分刷新的[A],然后按提交/保存,文档将被保存,页面将完全更新,文档将显示在下面的视图中。

但如果我将[A]设置为[B]刷新然后按提交/保存,则会保存文档,但文档不会出现在视图中。我需要通过在URL栏中按ENTER重新加载页面来更新视图。试图对此进行研究,但无济于事。

您认为我可以做些什么来更新最后一个场景的观点?

以下是简化代码:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom"
   style="font-size:11pt;font-weight:bold">

    <xp:this.beforePageLoad>
        <![CDATA[#{javascript:var currLocation=context.getUrl();
var webDBPath=@LeftBack(currLocation,"/");
sessionScope.jQuery=webDBPath+"/jquery.min.js";
sessionScope.jQueryUI=webDBPath+"/jquery-ui.min.js";
sessionScope.jQueryBlockUI=webDBPath+"/jquery.blockUI.js"}]]>
    </xp:this.beforePageLoad>

    <xp:this.data>

        <xp:dominoDocument var="attachmentDoc" formName="Attachment"></xp:dominoDocument>
    </xp:this.data>

    <xp:this.resources>
        <xp:script src="#{javascript:sessionScope.jQuery}"
         clientSide="true">
        </xp:script>
        <xp:script src="#{javascript:sessionScope.jQueryUI}"
         clientSide="true">
        </xp:script>
        <xp:script src="#{javascript:sessionScope.jQueryBlockUI}"
         clientSide="true">
        </xp:script>
        <xp:script src="/home.js" clientSide="true"></xp:script>
        <xp:styleSheet href="/style.css"></xp:styleSheet>
        <xp:styleSheet href="/jquery-ui.css"></xp:styleSheet>
        <xp:script src="/utils.jss" clientSide="false"></xp:script>
    </xp:this.resources>

    <xp:span style="font-weight:bold;font-size:11pt"></xp:span>
    <xp:span style="font-size:14pt"></xp:span>
    <xp:span style="font-weight:bold;font-size:11pt"></xp:span>
    <xp:inputText id="reUploadAttachmentID" style="display: none;"
      styleClass="reUploadAttachmentID"></xp:inputText>
    <xp:br style="font-size:11pt"></xp:br>
    <xp:panel style="margin-left:auto;margin-right:auto;width:940.0px"
      id="mainPanel">

        <xp:span style="font-size:14pt"></xp:span>
        <xp:span style="font-size:14pt"></xp:span>
        <xp:br style="font-weight:bold"></xp:br>
        <xp:br></xp:br>
        <xp:inputText id="errorMessage" value="#{requestScope.errorMessage}"
         styleClass="errorMessage"></xp:inputText>

        <xp:span style="font-weight:bold"></xp:span>
        <xp:span style="font-weight:bold">
            <xp:span style="font-weight:bold"></xp:span>
        </xp:span>
        <xp:br></xp:br>
        <xp:panel styleClass="upload-details-panel">
            <xp:span>Upload:</xp:span>
            <xp:fileUpload id="fileUpload1" value="#{attachmentDoc.Attachment}"></xp:fileUpload>
        </xp:panel>
        <xp:panel styleClass="upload-details-panel">
            <span>Type:</span>
            <xp:comboBox id="cbUploadType" value="#{attachmentDoc.File_Type}"
            styleClass="cbUploadType">
                <xp:selectItem itemLabel="Attachment"></xp:selectItem>
                <xp:selectItem itemLabel="eCR Master File"></xp:selectItem>

                <xp:selectItem itemLabel="Financial Analysis"></xp:selectItem>
                <xp:eventHandler event="onchange" submit="true"
               refreshMode="partial" refreshId="panelUploadDetails">
                </xp:eventHandler>
            </xp:comboBox>
        </xp:panel>

        <xp:panel id="panelUploadDetails">
            <xp:panel styleClass="upload-details-panel">
                <xp:this.rendered><![CDATA[#{javascript:var uploadType = getComponent("cbUploadType").getValue();
if(uploadType == "Attachment" || uploadType == null){
    return false;
}
return true;}]]></xp:this.rendered>
                <span>Division:</span>
                <xp:comboBox id="comboBox1" value="#{attachmentDoc.File_Database}"
               styleClass="cbUploadDatabase">
                    <xp:selectItems>
                        <xp:this.value><![CDATA[#{javascript:var options = ["---"];
return options.concat(@Unique(@DbColumn("", "eCR Database Settings", 1)));}]]></xp:this.value>
                    </xp:selectItems>
                    <xp:eventHandler event="onchange" submit="true"
                  refreshMode="partial"
                  refreshId='#{javascript:var uploadType = getComponent("cbUploadType").getValue();
if(uploadType == "Financial Analysis"){
    return "panelFAType";
}
return "panelExtra";
}'>

                    </xp:eventHandler>

                </xp:comboBox>

            </xp:panel>
            <xp:panel id="panelExtra">
                <!--
               this is just used to redirect partial refresh of Division
               Selection for non-FA
            -->
            </xp:panel>
            <xp:panel styleClass="upload-details-panel" id="panelFAType">

                <xp:this.rendered><![CDATA[#{javascript:var uploadType = getComponent("cbUploadType").getValue();
if(uploadType == "Financial Analysis"){
    return true;
}
return false;}]]></xp:this.rendered>
                <span>Financial Analysis Type:</span>
                <xp:comboBox id="comboBoxFAType" value="#{attachmentDoc.FAType}">
                    <xp:selectItems>
                        <xp:this.value><![CDATA[#{javascript:var division = getComponent("comboBox1").getValue();
if(division != null){
    return getFATypeOptions(getComponent("comboBox1").getValue());
}
return "---";}]]></xp:this.value>
                    </xp:selectItems>
                </xp:comboBox>
            </xp:panel>
        </xp:panel>
        <xp:panel styleClass="upload-details-panel">
            <span></span>
            <xp:button id="btnUpload" value="Upload" styleClass="btnUpload"
            style="height:26.0px">
                <xp:eventHandler event="onclick" submit="true"
               refreshMode="complete" immediate="false" save="true">
                    <xp:this.action><![CDATA[#{javascript:
var fileData:com.ibm.xsp.http.UploadedFile = facesContext.getExternalContext().getRequest().getParameterMap().get(getClientId('fileUpload1'));

var db:NotesDatabase = session.getCurrentDatabase();

var agent = database.getAgent("Import Data to Document");

//var attDoc:NotesDocument = attachmentDoc.getDocument();
//var doc:NotesDocument = db.createDocument(); 
var doc:NotesDocument = attachmentDoc.getDocument();
var settingsDoc:NotesDocument = db.getProfileDocument("eCRFilesDBConfiguration", "");

var repositoryPath:String;

if (fileData != null) {
   //doc.replaceItemValue('Form', 'Attachment');
   doc.computeWithForm(true, false);

    var clientFileName:String = fileData.getClientFileName();           
    var newFile:java.io.File = new java.io.File(fileData.getServerFileName());
    var filePath:string = doc.getItemValueString("File_Path");

    doc.replaceItemValue('File_Name', clientFileName);

    //   get file extension    
    var extension:string = '';
    var newFileName:string = '';
    var i:int;

   i = clientFileName.lastIndexOf('.');
   if (i > 0) {
       extension = clientFileName.substring(i+1);
   }  

   doc.replaceItemValue('File_Extension', extension);    
    newFileName = doc.getUniversalID() + '.' + extension;

   //var savedFile:java.io.File = new java.io.File('C:\\' + newFileName);
    //var savedFile:java.io.File = new java.io.File('C:\\' + clientFileName);

    repositoryPath = settingsDoc.getItemValueString("FileRepositoryPath")
    var savedFile:java.io.File = new java.io.File(repositoryPath + newFileName);

    newFile.renameTo(savedFile);

    doc.replaceItemValue("File_Size", savedFile.length())
    doc.replaceItemValue("Processed_eCR_Template", "");

    //   Save the new file
    if (savedFile.exists()) {
      // this is used to retain the icon/appearance of the attachment
      // in the document      
      //doc.replaceItemValue('Attachment', attDoc.getItemValue('Attachment'));

      doc.save(); 
    } else {
      //requestScope.errorMessage = 'Server file not found';
      print('Server file not found');
    }
} else {
   requestScope.errorMessage = 'No File found';
   print('No File found');
}

// this code prevents resubmit of the uploaded file when the user refreshes
// the page
// var curURL = window.location.href;
// var NSFURL = curURL.toLowerCase().split( '.nsf')[0] + '.nsf';


// window.location.href = NSFURL}]]></xp:this.action>
                    <xp:this.script><![CDATA[//validate fields before submission

var uploadType = document.getElementById("#{id:cbUploadType}").value;
if(uploadType == "Attachment"){
    return true;
}else{
    var division = document.getElementById("#{id:comboBox1}").value;
    if(division == "---"){
        alert("Please specify the division.");
        return false;
    }
    if(uploadType == "eCR Master File"){
        return true;
    }else if(uploadType == "Financial Analysis"){
        var faType = document.getElementById("#{id:comboBoxFAType}").value;
        if(faType == "---"){
            alert("Please specify the Financial Analysis Type.");
            return false;
        }else{
            return true;
        }
    }
}

//if upload type not rcognized
alert("Upload Type not recognized. Please contact you administrator.");
return false;

]]></xp:this.script>
                </xp:eventHandler>
            </xp:button>

        </xp:panel>
        <xp:panel id="panelUploadedFiles">

            <xp:viewPanel rows="30" id="viewPanel1" viewStyle="width:100%">
                <xp:this.facets>
                    <xp:pager partialRefresh="true" layout="Previous Group Next"
                  xp:key="headerPager" id="pager1">
                    </xp:pager>
                </xp:this.facets>
                <xp:this.data>
                    <xp:dominoView var="view1" viewName="Attachments For Web"
                  keys="#{javascript:@UserName()}" categoryFilter="File_Owner">
                    </xp:dominoView>
                </xp:this.data>

                <xp:viewColumn columnName="File_Name" id="viewColumn2">
                    <xp:viewColumnHeader value="File Name"
                  id="viewColumnHeader2">
                    </xp:viewColumnHeader>
                </xp:viewColumn>
                <xp:viewColumn columnName="Date_Uploaded" id="viewColumn3">
                    <xp:viewColumnHeader value="Date Uploaded"
                  id="viewColumnHeader3">
                    </xp:viewColumnHeader>
                </xp:viewColumn>
                <xp:viewColumn columnName="Last_Attached" id="viewColumn4">
                    <xp:viewColumnHeader value="Last Attached"
                  id="viewColumnHeader4">
                    </xp:viewColumnHeader>
                </xp:viewColumn>
            </xp:viewPanel>
        </xp:panel>
    </xp:panel>
    <xp:br></xp:br>
</xp:view>

触发部分刷新的元素是组合框(onchange)。保存按钮是“上传”按钮。面板panelUploadedFiles包含视图。

1 个答案:

答案 0 :(得分:2)

您需要发布示例代码,因为无法从初始问题中诊断出您的问题。

我建议接受“XPages MasterClass”培训。大概大约四个小时。它将向您展示如何使用XPages Toolbox,您可以使用它来调试这些类型的问题。

相关问题