内部重复的自定义控件在一个自定义属性中看不到rowData,但在其他自定义属性中工作

时间:2017-07-21 13:48:44

标签: xpages custom-controls xpages-ssjs

我有以下自定义控件:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:this.beforePageLoad><![CDATA[#{javascript:compositeData.id = this.getId();
if (!compositeData.body_class) {compositeData.body_class='panel-body'};
if (!compositeData.panel_id) {compositeData.panel_id='section'+compositeData.id};}]]></xp:this.beforePageLoad>
    <xp:panel>
        <xp:this.styleClass><![CDATA[#{javascript:"ccSectionPanel panel " + compositeData.panel_class + ""}]]></xp:this.styleClass>
            <xp:this.attrs>
                <xp:attr name="id">
                    <xp:this.value><![CDATA[#{javascript:compositeData.panel_id}]]></xp:this.value>
                </xp:attr>
            </xp:this.attrs>
        <xp:panel styleClass="panel-heading" style="cursor:pointer;">
            <xp:this.attrs>
                <xp:attr name="id">
                    <xp:this.value><![CDATA[#{javascript:compositeData.panel_id + "_heading"}]]></xp:this.value>
                </xp:attr>
                <xp:attr name="href">
                    <xp:this.value><![CDATA[#{javascript:"#" + compositeData.panel_id + "_section"}]]></xp:this.value>
                </xp:attr>
                <xp:attr name="data-toggle" value="collapse"></xp:attr>
            </xp:this.attrs>


            <xp:link escape="true" styleClass="panel-title"
                text="#{javascript:compositeData.titleBarText}">
                <xp:this.attrs>
                    <xp:attr name="id">
                        <xp:this.value><![CDATA[#{javascript:compositeData.panel_id + "_title"}]]></xp:this.value>
                    </xp:attr>
                </xp:this.attrs>
                <xp:this.id><![CDATA[${javascript:compositeData.panel_id + "_title"}]]></xp:this.id>
            </xp:link>
        </xp:panel>

        <xp:panel>
            <xp:this.styleClass><![CDATA[#{javascript:"panel-collapse collapse" + (compositeData.initClosed ? "" : " in")}]]></xp:this.styleClass>
            <xp:this.attrs>
                <xp:attr name="id">
                    <xp:this.value><![CDATA[#{javascript:compositeData.panel_id + "_section"}]]></xp:this.value>
                </xp:attr>
            </xp:this.attrs>
            <xp:panel
                styleClass="#{javascript:compositeData.body_class}">
                <xp:callback facetName="panelBody" id="panelBody"></xp:callback>
            </xp:panel>
            <xp:panel rendered="#{javascript:compositeData.footer}"
                styleClass="panel-footer">
                <xp:callback facetName="panelFooter" id="panelFooter"></xp:callback>
            </xp:panel>
        </xp:panel>
    </xp:panel>
</xp:view>

我在重复控制中使用它:

<xp:repeat id="repeat1" rows="30" value="#{view1}"
                    var="repEntry" indexVar="index" repeatControls="false">
                    <xp:panel>
                        <xp:this.data>
                            <xp:dominoDocument var="doc"
                                action="openDocument"
                                documentId="#{javascript:repEntry.getNoteID()}"
                                ignoreRequestParams="true">
                            </xp:dominoDocument>
                        </xp:this.data>
                        <xc:ccSectionPanel initClosed="false"
                            panel_class="#{javascript:repEntry.getColumnValue('class')}"
                            footer="#{javascript:sessionScope.isAdmin}"
                            rendered="#{javascript:repEntry.getColumnValue('Status') == '1' || sessionScope.isAdmin}">
                            <xc:this.titleBarText><![CDATA[#{javascript:repEntry.getColumnValue('Title') + (repEntry.getColumnValue('Status') != '1' ? ' (скрыто)' : '')

}]]></xc:this.titleBarText>
                            <xp:this.facets>
                                <xp:panel xp:key="panelFooter">

                                    <xp:button value="Редактировать"
                                        id="button2" styleClass="btn btn-xs">
                                        <i
                                            class="glyphicon glyphicon-pencil">
                                        </i>
                                        <xp:eventHandler event="onclick"
                                            submit="true" refreshMode="complete">
                                            <xp:this.action>
                                                <xp:openPage
                                                    name="/index.xsp" target="editDocument"
                                                    documentId="#{javascript:repEntry.getNoteID()}">
                                                </xp:openPage>
                                            </xp:this.action>
                                        </xp:eventHandler>
                                    </xp:button>
                                    <xp:button
                                        value="#{javascript:repEntry.getColumnValue('Status') != '1' ? 'Показать' : 'Скрыть'}"
                                        id="button3" styleClass="#{javascript:'btn btn-xs'}">
                                        <i
                                            class="#{javascript:repEntry.getColumnValue('Status') != '1' ? 'glyphicon glyphicon-eye-open' : 'glyphicon glyphicon-eye-close'}">
                                        </i>
                                        <xp:eventHandler event="onclick"
                                            submit="true" refreshMode="partial" disableValidators="true"
                                            refreshId="content">
                                            <xp:this.action><![CDATA[#{javascript:if (repEntry.getColumnValue('Status') == '1') {
    doc.replaceItemValue('Status','0');
    doc.replaceItemValue('Author',sessionScope.User.UserName);
    doc.save();
} else {
    doc.replaceItemValue('Status','1');
    doc.replaceItemValue('Author',sessionScope.User.UserName);
    doc.save();
}}]]></xp:this.action>
                                        </xp:eventHandler>
                                    </xp:button>
                                    <xp:text escape="false"
                                        id="computedField2" styleClass="btn btn-xs">
                                        <xp:this.value><![CDATA[#{javascript:'<i class="glyphicon glyphicon-user"></i>' + repEntry.getColumnValue('Author') + '  <i class="glyphicon glyphicon-time"></i>' + repEntry.getColumnValue('$1')
}]]></xp:this.value>
                                    </xp:text>
                                </xp:panel>
                                <xp:panel xp:key="panelBody">
                                    <!-- <xp:this.data>
                                        <xp:dominoDocument var="doc" action="openDocument"
                                        documentId="#{javascript:repEntry.getNoteID()}" 
                                        ignoreRequestParams="true">
                                        </xp:dominoDocument>
                                        </xp:this.data> -->
                                    <xp:inputRichText
                                        id="inputRichText2" value="#{doc.Body}" readonly="true"
                                        rendered="false">
                                    </xp:inputRichText>
                                    <xp:text escape="false"
                                        id="computedField1">
                                        <xp:this.value><![CDATA[#{javascript:doc.getDocument().getFirstItem("Body").getMIMEEntity().getContentAsText(); }]]></xp:this.value>
                                    </xp:text>


                                </xp:panel>
                            </xp:this.facets>
                        </xc:ccSectionPanel>
                    </xp:panel>
                </xp:repeat>

当我设置cumputed属性时, (picture) 它工作正常,但是当我将panel_id设置为相对于repEntry或doc的某些内容时,它会抛出错误(repEntry未定义)。我可以设置“在创建页面时创建控件”,但是我失去了部分刷新的优势。

主要问题,为什么一个costom属性可以与repEntry一起使用,但是其他不可以?

1 个答案:

答案 0 :(得分:0)

答案归结为财产的计算时间。计算它并在SSJS代码中添加一个print语句,你就会看到。在组件加载时需要计算ID,因此在处理的最早阶段。最重要的是,这是因为它生成了一组抽象的组件,而不是与特定的行条目相关联,因为它还没有构建集合。可以把它想象成在从它创建对象之前创建一个抽象类。