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

时间:2015-06-12 15:47:08

标签: xpages attachment

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

tmpDoc.getAttachment("attachments")

获取附件。但没有任何表现。

以下是对话框中表格中一行的代码。

其他字段工作正常,我知道我正在获取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 Build的rspPCTask表单。

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

下面是一个截屏。在第二个领域,我正在用javascript抓取一些东西。在第一个字段中,我将字段绑定到数据源,但它始终为空白。我无法弄清楚原因。

enter image description here

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

<?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>

3 个答案:

答案 0 :(得分:2)

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

我所知道的关于这件事的一切我从这篇文章中学到了:http://www.wissel.net/blog/d6plinks/SHWL-86QKNM

答案 1 :(得分:2)

在fileDowndload控件中显示“另一个”文档的所有富文本字段附件:

  • 在fileDownload控件
  • 周围添加面板
  • dominoDocument 数据源添加到面板
    将属性documentId设置为“另一个”文档的UNID
  • fileDownload value设置为文档的富文本字段
    (在您的情况下,富文本字段称为“附件”)
<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>
您使用的BTW tmpDoc.getAttachment("attachments")不会返回富文本字段“附件”的所有附件,但会在文档中的某处找到文件名为“附件”的attachment

答案 2 :(得分:0)

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