【问题标题】:Custom control inside repeat can't see rowData in one custom property, but work in other重复中的自定义控件在一个自定义属性中看不到 rowData,但在其他自定义属性中可以使用
【发布时间】:2017-07-21 13:48:44
【问题描述】:

我有以下自定义控件:

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

当我设置累积属性时, 它可以工作,但是当我将 panel_id 设置为与 repEntry 或 doc 相关的内容时,它会引发错误(repEntry 未定义)。我可以设置“在页面创建时创建控件”,但是我失去了部分刷新的优势。

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

【问题讨论】:

  • “panel_id”是什么属性类型?您为属性“panel_id”设置了哪个值?
  • 字符串和字符串。问题是为什么它不能使用行变量,但另一个可以。
  • 我尝试设置值: 1. repEntry.getPosition('.'); 2.repEntry.getUniversalID(); 3. doc.getNoteId(); doc 未定义,repEntry 未定义

标签: xpages custom-controls xpages-ssjs


【解决方案1】:

答案归结为何时计算属性。计算它并在 SSJS 代码中添加一个打印语句,你会看到。加载组件时需要计算 ID,因此在处理的最早部分。最重要的是,它正在生成一个抽象的组件集,与特定的行条目无关,因为它还没有构建集合。可以把它想象成在从它创建对象之前创建一个抽象类。

【讨论】:

  • 如果您尝试打印与重复相关的内容,它会。如果我无法调试并且我想显示处理顺序,我使用类似print("Computing ID"); 的东西然后在重复中添加类似print("Loading repeat values"); 的东西。这将显示处理顺序以及它是否在迭代值之前尝试计算 ID。您将在我提供的这个 TLCC 网络研讨会youtube.com/watch?v=t7j_MR5uzCA&feature=youtu.be 中看到更详细的介绍。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-26
  • 2015-07-27
  • 1970-01-01
  • 1970-01-01
  • 2011-03-20
  • 2017-02-15
  • 1970-01-01
相关资源
最近更新 更多