无法将图像嵌入到Xpage中的动态绑定的richtext项目中

时间:2017-08-10 10:11:04

标签: xpages lotus-domino domino-designer-eclipse

我有一个测验表单,可以创建不同的心理测试。现在它硬编码到50个问题。我需要一些问题来嵌入图像,这就是我使用RichText的原因。当我使用value="#{document1[viewScope.FieldName]}"动态绑定它时,它可以正常使用自定义文本格式,但不要让我将图像导入到richtext中。使用value="${document1[viewScope.FieldName]}"绑定,但我无法动态更改字段。

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

    <xp:this.data>
        <xp:dominoDocument var="document1" formName="test">

        </xp:dominoDocument>
    </xp:this.data>

    <xp:this.beforePageLoad><![CDATA[#{javascript:if (!viewScope.qNum || viewScope.qNum == 0) {
    viewScope.qNum = 1;
}
viewScope.qFNCount = 'Q'+viewScope.qNum + 'Count';
viewScope.qFNCorrect = 'Q'+viewScope.qNum + 'Correct';
viewScope.qFNTitle = 'Q'+viewScope.qNum + 'Title';
viewScope.qFNA1 = 'Q'+viewScope.qNum + 'A1';
viewScope.qFNA2 = 'Q'+viewScope.qNum + 'A2';
viewScope.qFNA3 = 'Q'+viewScope.qNum + 'A3';
viewScope.qFNA4 = 'Q'+viewScope.qNum + 'A4';
viewScope.qFNA5 = 'Q'+viewScope.qNum + 'A5';}]]></xp:this.beforePageLoad>
    <xp:this.beforeRenderResponse><![CDATA[#{javascript:
viewScope.qFNCount = 'Q'+viewScope.qNum + 'Count';
viewScope.qFNCorrect = 'Q'+viewScope.qNum + 'Correct';
viewScope.qFNTitle = 'Q'+viewScope.qNum + 'Title';
viewScope.qFNA1 = 'Q'+viewScope.qNum + 'A1';
viewScope.qFNA2 = 'Q'+viewScope.qNum + 'A2';
viewScope.qFNA3 = 'Q'+viewScope.qNum + 'A3';
viewScope.qFNA4 = 'Q'+viewScope.qNum + 'A4';
viewScope.qFNA5 = 'Q'+viewScope.qNum + 'A5';}]]></xp:this.beforeRenderResponse>
    <xp:scriptBlock id="scriptBlock2">
    <xp:this.value>
        <![CDATA[
            CKEDITOR.config.removeButtons = 'TextColor,BGColor,Find,Font,Underline,Subscript,Superscript,Scayt,Anchor,Table,HorizontalRule,SpecialChar,Maximize,Strike,NumberedList,BulletedList,Indent,Outdent,Blockquote,Styles,Format,About';
        ]]>
    </xp:this.value>
</xp:scriptBlock>


    <xp:this.resources>
        <xp:styleSheet href="/application.css"></xp:styleSheet>
        <xp:script src="/core.ssjs.jss" clientSide="false"></xp:script>
        <xp:script src="/client.js" clientSide="true"></xp:script>
        <xp:script src="/form.js" clientSide="true"></xp:script>
    </xp:this.resources>

    <xp:panel styleClass="container form-horizontal" id="container">

        <xe:djHorizontalSlider id="djHorizontalSlider1"
            value="#{viewScope.qNum}" clickSelect="true" maximum="50" minimum="1"
            pageIncrement="1" showButtons="true" required="true"
            style="overflow:hidden" readOnly="false" discreteValues="50"
            lang="ru" slideDuration="50">
            <xe:this.converter>
                <xp:convertNumber integerOnly="true"></xp:convertNumber>
            </xe:this.converter>
            <xe:djSliderRuleLabels
                style="height:14px;font-size:75%;color:gray" count="50"
                container="bottomDecoration" id="djSliderRuleLabels1" maximum="50"
                minimum="1" labels="#{javascript:rangeStr(1,51)}">

            </xe:djSliderRuleLabels>


            <xp:eventHandler event="onChange" submit="true"
                refreshMode="complete">
                <xe:this.action><![CDATA[#{javascript:viewScope.qFNTitle = 'Q'+viewScope.qNum + 'Title';
viewScope.qFNCount = 'Q'+viewScope.qNum + 'Count';
viewScope.qFNCorrect = 'Q'+viewScope.qNum + 'Correct';
viewScope.qFNA1 = 'Q'+viewScope.qNum + 'A1';
viewScope.qFNA2 = 'Q'+viewScope.qNum + 'A2';
viewScope.qFNA3 = 'Q'+viewScope.qNum + 'A3';
viewScope.qFNA4 = 'Q'+viewScope.qNum + 'A4';
viewScope.qFNA5 = 'Q'+viewScope.qNum + 'A5';}]]></xe:this.action>
            </xp:eventHandler>
        </xe:djHorizontalSlider>
        <xp:panel styleClass="panel panel-default" id="quests">
            <xp:panel styleClass="panel-body">
                <xc:ccSectionPanel panel_id="ccSection"
                    initClosed="false" panel_class="panel-default" footer="false"
                    disable_collapse="true"
                    titleBarText="#{javascript:'Вопрос номер ' + viewScope.qNum;}"
                    custom_title="true">
                    <xp:this.facets>
                        <xp:panel xp:key="customTitle">
                        <xp:text escape="true" id="computedField1"
                            value="#{javascript:'Вопрос номер ' + viewScope.qNum;}"
                            styleClass="panel-title">
                        </xp:text>
                        <xp:button value="Редактировать" id="button2"
                            rendered="#{javascript:document1.isEditable()==@False()}"
                            styleClass="pull-right"
                            style="margin-top:-7px;margin-right:-12px;">

                            <xp:eventHandler event="onclick"
                                submit="true" refreshMode="complete">
                                <xp:this.action>

                                    <xp:actionGroup>
                                        <xp:changeDocumentMode
                                            mode="edit" var="document1">
                                        </xp:changeDocumentMode>
                                        <xp:executeScript>
                                            <xp:this.script><![CDATA[#{javascript:viewScope.put("editmode", true)}]]></xp:this.script>
                                        </xp:executeScript>
                                    </xp:actionGroup>
                                </xp:this.action>
                            </xp:eventHandler>
                        </xp:button>
                        <xp:button value="Сохранить" id="button1"
                            rendered="#{javascript:document1.isEditable()}"
                            styleClass="pull-right"
                            style="margin-top:-7px;margin-right:-12px;">
                            <xp:eventHandler event="onclick"
                                submit="true" refreshMode="complete">
                                <xp:this.action>


                                    <xp:actionGroup>
                                        <xp:actionGroup>
                                            <xp:saveDocument
                                                var="document1">
                                            </xp:saveDocument>
                                            <xp:changeDocumentMode
                                                mode="readOnly" var="document1">
                                            </xp:changeDocumentMode>
                                        </xp:actionGroup>
                                        <xp:executeScript>
                                            <xp:this.script><![CDATA[#{javascript:viewScope.put("editmode", false)}]]></xp:this.script>
                                        </xp:executeScript>
                                    </xp:actionGroup>
                                </xp:this.action>
                            </xp:eventHandler>
                        </xp:button>
                        </xp:panel>
                        <xp:panel xp:key="panelBody">
                            <xc:ссFormGroup fg_id="fgTitle"
                                editmode="true" label_target="inputRichTextTitle">
                                <xc:this.label_text><![CDATA[#{javascript:'Заголовок вопроса [' + viewScope.qFNTitle + ']'}]]></xc:this.label_text>
                                <xp:this.facets>
                                    <xp:inputRichText
                                        id="inputRichTextTitle" xp:key="fieldFacet"
                                        value="#{document1[viewScope.qFNTitle]}">
                                    </xp:inputRichText>
                                </xp:this.facets>
                            </xc:ссFormGroup>
                            <xc:ссFormGroup fg_id="fgCountAnswers"
                                editmode="true" label_target="radioGroup1">
                                <xc:this.label_text><![CDATA[#{javascript:'Количество вариантов ответа [' + viewScope.qFNCount + ']'}]]></xc:this.label_text>
                                <xp:this.facets>
                                    <xp:radioGroup id="radioGroup1"
                                        xp:key="fieldFacet" defaultValue="4"
                                        value="#{document1[viewScope.qFNCount]}">
                                        <xp:selectItem itemLabel="1"></xp:selectItem>
                                        <xp:selectItem itemLabel="2"></xp:selectItem>
                                        <xp:selectItem itemLabel="3"></xp:selectItem>
                                        <xp:selectItem itemLabel="4"></xp:selectItem>
                                        <xp:selectItem itemLabel="5"></xp:selectItem>
                                        <xp:eventHandler
                                            event="onchange" submit="true" refreshMode="partial"
                                            refreshId="container">
                                        </xp:eventHandler>
                                    </xp:radioGroup>
                                </xp:this.facets>
                            </xc:ссFormGroup>
                            <xc:ссFormGroup fg_id="fgA1" editmode="true"
                                label_target="inputRichTextA1">
                                <xc:this.label_text><![CDATA[#{javascript:'Ответ 1 [' + viewScope.qFNA1 + ']'}]]></xc:this.label_text>
                                <xp:this.facets>
                                    <xp:inputRichText
                                        id="inputRichTextA1" xp:key="fieldFacet"
                                        value="#{document1[viewScope.qFNA1]}">
                                    </xp:inputRichText>
                                </xp:this.facets>
                            </xc:ссFormGroup>


                            <xc:ссFormGroup fg_id="fgA2" editmode="true"
                                label_target="inputRichTextA2">
                                <xc:this.rendered><![CDATA[#{javascript:count = document1.getItemValueString(viewScope.qFNCount);
if (!count || count == '') {count = 4}
count > 1}]]></xc:this.rendered>
                                <xc:this.label_text><![CDATA[#{javascript:'Ответ 2 [' + viewScope.qFNA2 + ']'}]]></xc:this.label_text>
                                <xp:this.facets>
                                    <xp:inputRichText
                                        id="inputRichTextA2" xp:key="fieldFacet"
                                        value="#{document1[viewScope.qFNA2]}">
                                    </xp:inputRichText>
                                </xp:this.facets>
                            </xc:ссFormGroup>


                            <xc:ссFormGroup fg_id="fgA3" editmode="true"
                                label_target="inputRichTextA3">
                                <xc:this.rendered><![CDATA[#{javascript:count = document1.getItemValueString(viewScope.qFNCount);
if (!count || count == '') {count = 4}
count > 2}]]></xc:this.rendered>
                                <xc:this.label_text><![CDATA[#{javascript:'Ответ 3 [' + viewScope.qFNA3 + ']'}]]></xc:this.label_text>
                                <xp:this.facets>
                                    <xp:inputRichText
                                        id="inputRichTextA3" xp:key="fieldFacet"
                                        value="#{document1[viewScope.qFNA3]}">


                                    </xp:inputRichText>
                                </xp:this.facets>
                            </xc:ссFormGroup>


                            <xc:ссFormGroup fg_id="fgA4" editmode="true"
                                label_target="inputRichTextA4">
                                <xc:this.rendered><![CDATA[#{javascript:count = document1.getItemValueString(viewScope.qFNCount);
if (!count || count == '') {count = 4}
count > 3}]]></xc:this.rendered>
                                <xc:this.label_text><![CDATA[#{javascript:'Ответ 4 [' + viewScope.qFNA4 + ']'}]]></xc:this.label_text>
                                <xp:this.facets>
                                    <xp:inputRichText
                                        id="inputRichTextA4" xp:key="fieldFacet"
                                        value="#{document1[viewScope.qFNA4]}">
                                    </xp:inputRichText>
                                </xp:this.facets>
                            </xc:ссFormGroup>


                            <xc:ссFormGroup fg_id="fgA5" editmode="true"
                                label_target="inputRichTextA5">
                                <xc:this.rendered><![CDATA[#{javascript:count = document1.getItemValueString(viewScope.qFNCount);
if (!count || count == '') {count = 4}
count > 4}]]></xc:this.rendered>
                                <xc:this.label_text><![CDATA[#{javascript:'Ответ 5 [' + viewScope.qFNA5 + ']'}]]></xc:this.label_text>
                                <xp:this.facets>
                                    <xp:inputRichText
                                        id="inputRichTextA5" xp:key="fieldFacet"
                                        value="#{document1[viewScope.qFNA5]}">
                                    </xp:inputRichText>
                                </xp:this.facets>
                            </xc:ссFormGroup>



                            <xc:ссFormGroup fg_id="fg1" editmode="true"
                                label_target="radioGroupCorrect">
                                <xc:this.label_text><![CDATA[#{javascript:'Верный ответ [' + viewScope.qFNCorrect + ']'}]]></xc:this.label_text>
                                <xp:this.facets>
                                    <xp:radioGroup
                                        id="radioGroupCorrect" xp:key="fieldFacet"
                                        value="#{document1[viewScope.qFNCorrect]}">
                                        <xp:selectItems>
                                            <xp:this.value><![CDATA[#{javascript:var count = document1.getItemValueString(viewScope.qFNCount);
if (!count || count == '') {count = 4}
count++;
rangeStr(1,count)}]]></xp:this.value>
                                        </xp:selectItems>
                                    </xp:radioGroup>
                                </xp:this.facets>
                            </xc:ссFormGroup>
                        </xp:panel>
                    </xp:this.facets>

                </xc:ccSectionPanel>
            </xp:panel>
        </xp:panel>
    </xp:panel></xp:view>

最简单,最残酷的解决方案是使用动态渲染状态创建50 * 7个静态字段。还有其他办法吗?

1 个答案:

答案 0 :(得分:3)

另一种可能更好的方法是在单独的文档中创建问题。然后,您不必动态绑定到字段。这是我至少在两次类似场合使用过的。

在一个文档中使用字段的驱动程序通常是习惯。传统的Domino Web或Notes客户端通常要求所有内容都在同一文档中。 XPages没有。打破习惯,你就解决了问题。

需要进行的一项更改是在添加问题之前创建并保存测验。有很多原因可以解释为什么这对于Web应用程序和带有大量问题的测验来说实际上是一种更好的方法。