Xpages 在另一个文档的对话框中显示附件

Xpages display attachment in dialog box from another document

我正在 Xpage 中打开一个对话框。在对话框中,我显示了 3 个其他文档的一些字段,并允许用户保存一些注释。所有这些都有效,除了我想显示附件(如果有的话)。我进入了一个文件下载控件,数据源指向目标文档,做了一个

tmpDoc.getAttachment("attachments")

获取附件。但是什么也没有出现。

这是对话框 table 中一行的代码。

其他字段工作正常,我知道我正在获取 tmpDoc,但如何显示附件以便用户可以查看?

<xp:td>
    <xp:fileDownload
        rows="30"
        id="fileDownload1"
        displayLastModified="false">
        <xp:this.value><![CDATA[#{javascript:
            var prtUNID:String = document.getItemValueString("PCTaskParentID");
            var tmpView:NotesView = database.getView("(dbAllPCTasksByTaskID)");
            var tmpDoc:NotesDocument = tmpView.getDocumentByKey(prtUNID);
            tmpDoc.getAttachment("attachments")
        }]]></xp:this.value>
    </xp:fileDownload>
</xp:td>

我对此有更多问题。现在它根本不起作用。

这是我想要完成的。

我有一个表格 PC Build。就是我公司组装PC必须完成的所有任务。有一个称为 PC 任务的主任务列表。保存新的 PC 构建时,PC 任务将复制到附加到 PC 构建的 rspPCTask 表单中。

当用户构建计算机时,他们可以打开 PC Build 并查看各个任务。我希望他们能够单击任务并从主任务中提取注释和附件,同时为单个任务输入注释。

下面是屏幕截图。在第二个字段中,我用 javascript 抓取了一些东西。在第一个字段中,我将该字段绑定到数据源,但它始终为空白。我不知道为什么。

我已经在下面输入了我的所有代码。任何帮助将不胜感激!!!

<?xml version="1.0" encoding="UTF-8"?>
<xp:view
    xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex"
    xmlns:xc="http://www.ibm.com/xsp/custom"
    dojoForm="true"
    dojoParseOnLoad="true"
    dojoTheme="true">
    <xp:this.data>
        <xp:dominoDocument
            var="document1"
            action="openDocument"
            computeWithForm="onsave"
            formName="PCBuild">
            <xp:this.postNewDocument>
                <xp:actionGroup>
                    <xp:setValue
                        binding="#{document1.ID}"
                        value="#{javascript:session.evaluate('@Unique')}" />
                    <xp:setValue
                        binding="#{document1.crtDte}"
                        value="#{javascript:session.evaluate('@Today')}" />
                    <xp:setValue
                        binding="#{document1.crtUsr}"
                        value="#{javascript:session.getCommonUserName()}" />
                </xp:actionGroup>
            </xp:this.postNewDocument>
        </xp:dominoDocument>
    </xp:this.data>
    <xp:this.resources>
        <xp:styleSheet
            href="/custom.css" />
        <xp:script
            src="/xpValidationPCBuild.jss"
            clientSide="false" />
        <xp:script
            src="/xpUtilities.jss"
            clientSide="false"></xp:script>
        <xp:styleSheet
            href="/.ibmxspres/dojoroot/dojox/grid/resources/tundraGrid.css">
        </xp:styleSheet>
        <xp:styleSheet
            href="/.ibmxspres/dojoroot/dojox/grid/resources/tundraEnhancedGrid.css">
        </xp:styleSheet>
        <xp:dojoModule
            name="dojox.grid.EnhancedGrid"></xp:dojoModule>
    </xp:this.resources>
    <xp:this.beforePageLoad><![CDATA[#{javascript:viewScope.ID = document1.getItemValueString("ID")}]]></xp:this.beforePageLoad>
    <xp:this.afterPageLoad><![CDATA[#{javascript:viewScope.put("rows","25")}]]></xp:this.afterPageLoad>
    <xp:panel
        style="width:900.00px">
        <xp:panel>
            <xp:text
                escape="true"
                id="dspDocUNID"
                style="display:none">
                <xp:this.value><![CDATA[#{javascript:if (@IsNewDoc()) 
{
return "0"
}
else
{
var doc:NotesDocument = document1.getDocument();
var sUNID = doc.getUniversalID();
return sUNID
}}]]></xp:this.value>
            </xp:text>
            <xp:scriptBlock
                id="scriptBlock1">
                <xp:this.value><![CDATA[// Conditionally return an image tag to display an icon in a cell
function displayIcon (value) {

  var image = '';
 switch (value.toLowerCase()) {
    case "open":
      image = '<img alt="" src="blueUncheckedCheckBox15.png" />';
      break;
     case "closed":
      image = '<img alt="" src="blueCheckedCheckBox15.png" />';
      break;
    default:
      image = '<img alt="" src="greenChk50.png" />';
      break;
  }
  return image;
}]]></xp:this.value>
            </xp:scriptBlock>
        </xp:panel>
        <xe:widgetContainer
            id="widgetContainerHeader">
            <xp:panel
                style="padding-top:8.0px;padding-bottom:8.0px">
                <xp:button
                    id="button1"
                    value="Edit"
                    style="font-weight:bold;font-size:10pt"
                    rendered="#{javascript:!(document1.isEditable())}">
                    <xp:eventHandler
                        event="onclick"
                        submit="true"
                        refreshMode="complete">
                        <xp:this.action>
                            <xp:changeDocumentMode
                                mode="edit" />
                        </xp:this.action>
                    </xp:eventHandler>
                </xp:button>
                <xp:button
                    value="Save"
                    id="button3"
                    style="font-weight:bold;font-size:10pt"
                    rendered="#{javascript:(document1.isEditable())}">
                    <xp:eventHandler
                        event="onclick"
                        submit="true"
                        refreshMode="partial"
                        refreshId="plContainer">
                        <xp:this.action>
                            <xp:actionGroup
                                condition="#{javascript:validateForm()}">
                                <xp:saveDocument
                                    var="document1"></xp:saveDocument>
                                <xp:executeScript>
                                    <xp:this.script><![CDATA[#{javascript://Get handle on current doc and see if it is a new doc
var thisDoc:NotesDocument = document1.getDocument();
var tg = thisDoc.getItemValueString("tasksGenerated");

if (tg != "Y") {

//Set flag to Y and save document
thisDoc.replaceItemValue("tasksGenerated","Y")
thisDoc.save(true)

var rspDoc:NotesDocument;

//Loop through all PC Task Docs

var pcTasksView:NotesView = database.getView("(dbAllPCTasks)");
var pcTaskDoc:NotesDocument = pcTasksView.getFirstDocument();
var tmpDoc:NotesDocument;
while (pcTaskDoc != null)
{
//Make new doc and add as response to this doc
rspDoc = database.createDocument();
rspDoc.replaceItemValue("Form","rspPCTask");
rspDoc.replaceItemValue("category",pcTaskDoc.getItemValueString("category"));
rspDoc.replaceItemValue("title",pcTaskDoc.getItemValueString("title"));
rspDoc.replaceItemValue("status","Open");
rspDoc.replaceItemValue("PCBuildParentID",thisDoc.getItemValueString("ID"));
rspDoc.replaceItemValue("PCTaskParentID",pcTaskDoc.getItemValueString("ID"));
rspDoc.replaceItemValue("PCTaskParentUNID",pcTaskDoc.getUniversalID());
rspDoc.replaceItemValue("order",pcTaskDoc.getItemValueInteger("order"));
rspDoc.save();

tmpDoc = pcTasksView.getNextDocument(pcTaskDoc);
pcTaskDoc.recycle();
pcTaskDoc = tmpDoc;
}
}}]]></xp:this.script>
                                </xp:executeScript>
                                <xp:openPage
                                    name="$$PreviousPage"></xp:openPage>
                            </xp:actionGroup>
                        </xp:this.action>
                    </xp:eventHandler>
                </xp:button>
                <xp:button
                    id="button2"
                    style="font-weight:bold;font-size:10pt"
                    value="Close">
                    <xp:eventHandler
                        event="onclick"
                        submit="true"
                        refreshMode="norefresh">
                        <xp:this.action>
                            <xp:openPage
                                name="$$PreviousPage"
                                target="openDocument" />
                        </xp:this.action>
                    </xp:eventHandler>
                </xp:button>
                <xp:text
                    escape="true"
                    id="computedField3"
                    style="font-size:14pt;color:rgb(79,79,79);padding-left:px;padding-bottom:px;margin-bottom:px;padding-right:25.0px">
                    <xp:this.value><![CDATA[#{javascript:document1.getItemValueString("crtDte")}]]></xp:this.value>
                </xp:text>
            </xp:panel>
        </xe:widgetContainer>
        <xp:panel
            id="plContainer">
            <xp:panel>
                <xe:widgetContainer
                    id="widgetContainerData">
                    <xe:formTable
                        id="frLocationMaster"
                        disableErrorSummary="true"
                        disableRowError="true">
                        <xp:this.facets>
                        </xp:this.facets>
                        <xe:formRow
                            id="formRow5"
                            labelPosition="none"
                            style="padding-bottom:10.0px">
                            <xp:table
                                style="width:99%"
                                border="0"
                                cellpadding="0"
                                role="presentation"
                                cellspacing="0"
                                id="table4">
                                <xp:tr>
                                    <xp:td
                                        style="width:80.0px;min-width:120px">
                                        <xp:text
                                            id="cfTitle"
                                            xp:key="header"
                                            style="font-size:14pt;color:rgb(79,79,79);padding-left:px;padding-bottom:px;margin-bottom:px">
                                            <xp:this.value><![CDATA[#{javascript:"PC Build"}]]></xp:this.value>
                                        </xp:text>
                                    </xp:td>
                                    <xp:td
                                        style="width:250.0px">
                                    </xp:td>
                                    <xp:td
                                        style="text-align:right">
                                        <xp:text
                                            escape="true"
                                            id="computedField1"
                                            style="font-size:14pt;color:rgb(79,79,79);padding-left:25.0px;padding-bottom:px;margin-bottom:px">
                                            <xp:this.value><![CDATA[#{javascript:document1.getItemValueString("crtUsr") + " on "}]]></xp:this.value>
                                            <xp:this.rendered><![CDATA[#{javascript:if (@IsNewDoc() == 1) {
return false
} else {
return true;
}}]]></xp:this.rendered>
                                        </xp:text>
                                        <xp:text
                                            escape="true"
                                            id="computedField2"
                                            style="font-size:14pt;color:rgb(79,79,79);padding-left:px;padding-bottom:px;margin-bottom:px;padding-right:px"
                                            value="#{document1.CrtDte}">
                                            <xp:this.converter>
                                                <xp:convertDateTime
                                                    type="both"
                                                    timeStyle="short" />
                                            </xp:this.converter>
                                            <xp:this.rendered><![CDATA[#{javascript:if (@IsNewDoc() == 1) {
return false
} else {
return true;
}}]]></xp:this.rendered>
                                        </xp:text>
                                    </xp:td>
                                </xp:tr>
                            </xp:table>
                        </xe:formRow>
                        <xe:formRow
                            id="formRow1"
                            labelPosition="none">
                            <xp:table
                                style="width:99%"
                                border="0"
                                cellpadding="0"
                                role="presentation"
                                cellspacing="0"
                                id="table3">
                                <xp:tr>
                                    <xp:td
                                        style="width:10%;min-width:120px;">
                                        <xp:label
                                            id="label4"
                                            for="formRow1"
                                            value="Employee Name" />
                                    </xp:td>
                                    <xp:td
                                        style="width:100px">
                                        <xp:inputText
                                            value="#{document1.employeeName}"
                                            id="employeeName1">
                                            <xp:typeAhead
                                                mode="full"
                                                minChars="1"
                                                valueListSeparator=","
                                                ignoreCase="true"
                                                id="typeAhead1">
                                                <xp:this.valueList><![CDATA[#{javascript:var dbname = new Array(@Subset(@DbName(), 1),"names.nsf");
return @DbColumn(dbname,"($PeopleByName)",1);}]]></xp:this.valueList>
                                            </xp:typeAhead>
                                        </xp:inputText>
                                    </xp:td>
                                    <xp:td
                                        style="width:20px">
                                        <xe:valuePicker
                                            id="valuePicker1"
                                            for="employeeName1"
                                            pickerIcon="/picker.png"
                                            dialogTitle="Choose Employee">
                                            <xe:this.dataProvider>
                                                <xe:simpleValuePicker>
                                                    <xe:this.valueList><![CDATA[#{javascript:var db:NotesDatabase = session.getDatabase(database.getServer(),"names.nsf");
var viewHandle:NotesView = db.getView("($PeopleByName)");
return viewHandle.getColumnValues(0)


}]]></xe:this.valueList>
                                                </xe:simpleValuePicker>
                                            </xe:this.dataProvider>
                                        </xe:valuePicker>
                                    </xp:td>
                                    <xp:td>
                                        <xp:message
                                            id="message1"
                                            for="employeeName1" />
                                    </xp:td>
                                </xp:tr>
                            </xp:table>
                        </xe:formRow>
                        <xe:formRow
                            id="formRow2"
                            labelPosition="none">
                            <xp:table
                                style="width:99%"
                                border="0"
                                cellpadding="0"
                                role="presentation"
                                cellspacing="0"
                                id="table1">
                                <xp:tr>
                                    <xp:td
                                        style="width:10%;min-width:120px;">
                                        <xp:label
                                            id="label1"
                                            for="formRow1"
                                            value="Computer Name" />
                                    </xp:td>
                                    <xp:td
                                        style="width:100px">
                                        <xp:inputText
                                            value="#{document1.computerName}"
                                            id="computerName1">
                                        </xp:inputText>
                                    </xp:td>
                                    <xp:td
                                        style="width:20px">
                                    </xp:td>
                                    <xp:td>
                                        <xp:message
                                            id="message2"
                                            for="computerName1" />
                                    </xp:td>
                                </xp:tr>
                            </xp:table>
                        </xe:formRow>
                        <xe:formRow
                            id="formRow3"
                            labelPosition="none"
                            rendered="false">
                        </xe:formRow>
                        <xe:formRow
                            id="formRow4"
                            labelPosition="none"
                            rendered="false">
                        </xe:formRow>
                    </xe:formTable>
                </xe:widgetContainer>
            </xp:panel>
        </xp:panel>
        <xp:panel>
            <xe:widgetContainer
                id="widgetContainer1">
                <xp:panel>
                    <xp:viewPanel
                        rows="30"
                        id="viewPanel1"
                        var="thisEntry">
                        <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="(dbAllRpPCTasks)">
                                <xp:this.keys><![CDATA[#{javascript:document1.getItemValueString("ID")}]]></xp:this.keys>
                            </xp:dominoView>
                        </xp:this.data>
                        <xp:viewColumn
                            columnName="title"
                            id="viewColumn5"
                            displayAs="link">
                            <xp:viewColumnHeader
                                value="Title"
                                id="viewColumnHeader5">
                            </xp:viewColumnHeader>
                            <xp:eventHandler
                                event="onclick"
                                submit="false"
                                refreshMode="partial"
                                refreshId="panelDig">
                                <xp:this.action><![CDATA[#{javascript:viewScope.UNID = thisEntry.getDocument().getUniversalID();
viewScope.parUNID = thisEntry.getDocument().getItemValueString("PCTaskParentUNID");
getComponent('dialog1').show()}]]></xp:this.action>
                            </xp:eventHandler>
                        </xp:viewColumn>
                    </xp:viewPanel>
                    <xp:panel
                        id="panelDig">
                        <xp:this.data>
                            <xp:dominoDocument
                                var="document2"
                                formName="PCTask"
                                action="editDocument"
                                documentId="#{javascript:viewScope.parUNID}">
                            </xp:dominoDocument>
                            <xp:dominoDocument
                                var="document3"
                                formName="rspPCTask"
                                action="editDocument"
                                documentId="#{javascript:viewScope.parUNID}">
                            </xp:dominoDocument>
                        </xp:this.data>
                        <xe:dialog
                            id="dialog1"
                            style="width:700px;height:600px"
                            refreshOnShow="true">
                            <xp:table>
                                <xp:tr>
                                    <xp:td>
                                        <xp:label
                                            value="Master Title"
                                            id="label2" />
                                    </xp:td>
                                    <xp:td>
                                        <xp:text
                                            escape="true"
                                            id="computedField4"
                                            value="#{document2.title}">
                                        </xp:text>
                                    </xp:td>
                                </xp:tr>
                                <xp:tr>
                                    <xp:td>
                                        <xp:label
                                            value="Master Task Notes"
                                            id="label3" />
                                    </xp:td>
                                    <xp:td>
                                        <xp:text
                                            escape="true"
                                            id="computedField5">
                                            <xp:this.value><![CDATA[#{javascript:var tmpDoc:NotesDocument = database.getDocumentByUNID(viewScope.parUNID)
tmpDoc.getItemValueString("notes")}]]></xp:this.value>
                                        </xp:text>
                                    </xp:td>
                                </xp:tr>
                                <xp:tr>
                                    <xp:td>
                                        <xp:label
                                            value="Master Attachments"
                                            id="label5" />
                                    </xp:td>
                                    <xp:td></xp:td>
                                </xp:tr>
                                <xp:tr>
                                    <xp:td></xp:td>
                                    <xp:td></xp:td>
                                </xp:tr>
                                <xp:tr>
                                    <xp:td>
                                        <xp:label
                                            id="label7"
                                            value="Notes" />
                                    </xp:td>
                                    <xp:td>
                                        <xp:inputTextarea
                                            id="inputTextarea1"
                                            style="width:98.0%;height:100px"
                                            value="#{document3.notes}">
                                        </xp:inputTextarea>
                                    </xp:td>
                                </xp:tr>
                            </xp:table>
                        </xe:dialog>
                    </xp:panel>
                </xp:panel>
            </xe:widgetContainer>
        </xp:panel>
    </xp:panel>
    <xp:eventHandler
        event="onClientLoad"
        submit="true"
        refreshMode="norefresh">
        <xp:this.script><![CDATA[try {
 dojo.byId("#{id:employeeName1}").focus();
} catch (e) { }]]></xp:this.script>
    </xp:eventHandler>
</xp:view>

如果可能我会避免文件下载控制。您可能想要做的只是为实际文件本身构建 html 链接或图像。所以这主要是找出正确的 URL 来实现它。通常这些都是老派 "non XPages" URL 的......经典的多米诺骨牌。

我所知道的关于做这件事的一切都是我从这个post中学到的:http://www.wissel.net/blog/d6plinks/SHWL-86QKNM

简答:您可以将 tmpDoc 添加为真正的文档数据源(使用

显示文件中 "another" 文档的所有富文本字段附件下载控件:

  • 在您的文件下载控件周围添加一个 面板
  • 向面板添加一个 dominoDocument 数据源
    将属性 documentId 设置为 "another" 文档的 UNID
  • fileDownloadvalue 设置为文档的富文本字段
    (在您的情况下,富文本字段称为 "attachments")
<xp:td>
    <xp:panel>
        <xp:this.data>
            <xp:dominoDocument
                var="documentPCTaskParent"
                action="openDocument">
                <xp:this.documentId><![CDATA[#{javascript:
                    document.getItemValueString("PCTaskParentID")
                }]]></xp:this.documentId>
            </xp:dominoDocument>
        </xp:this.data>
        <xp:fileDownload
            rows="30"
            id="fileDownload1"
            displayLastModified="false"
            value="#{documentPCTaskParent.attachments}">
        </xp:fileDownload>
    </xp:panel>
</xp:td>

顺便说一句 tmpDoc.getAttachment("attachments") 您使用的不是 return 富文本字段 "attachments" 的所有附件,而是会查找文件名 "attachments" 的 attachment ] 文档中某处。