如何在没有文档上下文的对话框中显示验证错误?

时间:2014-10-02 08:19:58

标签: xpages lotus-domino

我有一个Xpage,其中的字段连接到文档上下文,用户要在其中输入值并将其提交到数据库。

此外,还有一个按钮,显示扩展库中的对话框。该对话框包含所需的其他字段和其他验证器(正则表达式)。关闭此对话框的按钮是类型Button,事件上的SSJS仅将对话框字段中的值传输到下面的表单。

我面临的问题是字段上的验证器已执行但对话框中未显示错误。我可以告诉他们已被执行,因为无法关闭对话框。当没有显示错误消息时,这将使用户感到困惑。我已经使用错误消息控件,错误消息控件进行了测试,并且还启用了客户端验证。

如何在对话框中的对话框/错误消息控件中显示验证?

对话框:

<xe:dialog
            id="dialogNewSec"
            title="New Security Request"
        >
            <xe:dialogContent id="dialogContent1">
                <xe:formTable
                    id="formTable2"
                    labelPosition="above"
                    formDescription="Fields marked with * are mandatory"
                >
                    <xp:this.facets></xp:this.facets>
                    <xp:messages id="messages1"></xp:messages>
                    <xe:formRow
                        id="formRow1"
                        label="ISIN:"
                        for="inputText1"
                    >

                        <xp:inputText
                            id="inputText1"
                            required="true"
                            disableClientSideValidation="false"
                            maxlength="12"
                        >
                            <xp:this.validators>
                                <xp:validateRequired message="ISIN is required"></xp:validateRequired>
                                <xp:validateLength
                                    maximum="12"
                                    message="ISIN must not be more than 12 characters"
                                >
                                </xp:validateLength>
                                <xp:validateConstraint message="ISIN is incorrect">
                                    <xp:this.regex><![CDATA[/^[A-Z]{2}/]]></xp:this.regex>
                                </xp:validateConstraint>
                            </xp:this.validators>
                            <xp:eventHandler
                                event="onchange"
                                submit="false"
                            >
                                <xp:this.script><![CDATA[var e = window.document.getElementById("#{id:inputText1}");
e.value = e.value.toUpperCase();]]></xp:this.script>
                            </xp:eventHandler>
                        </xp:inputText><xp:message id="message1" for="inputText1"></xp:message>
                        <xp:this.facets></xp:this.facets>
                    </xe:formRow>
                    <xe:formRow
                        id="formRow3"
                        label="Exchange:"
                        for="comboBox1"
                    >
                        <xp:comboBox
                            id="comboBox1"
                            disableClientSideValidation="false"
                            required="true"
                        >
                            <xp:this.validators>
                                <xp:validateRequired message="Exchange is required"></xp:validateRequired>
                            </xp:this.validators>
                            <xp:selectItem
                                itemValue=""
                                itemLabel="*Select an Exchange*"
                            >
                            </xp:selectItem>
                            <xp:selectItems>
                                <xp:this.value><![CDATA[#{javascript:var values = DbColumnArray("", "", "cache", "unique", "", "vExchangeLookup", 3)+"|"+DbColumnArray("", "", "cache", "unique", "", "vExchangeLookup", 2);
return values;}]]></xp:this.value>
                            </xp:selectItems>
                        </xp:comboBox>
                    </xe:formRow>
                    <xe:formRow
                        id="formRow4"
                        label="Currency:"
                        for="comboBox2"
                    >
                        <xp:comboBox
                            id="comboBox2"
                            disableClientSideValidation="false"
                        >
                            <xp:this.validators>
                                <xp:validateRequired message="Currency must have a value"></xp:validateRequired>
                            </xp:this.validators>
                            <xp:selectItem
                                itemLabel="* Select a currency *"
                                itemValue=""
                            >
                            </xp:selectItem>
                            <xp:selectItems>
                                <xp:this.value><![CDATA[#{javascript:@DbColumn("","vCurrLookup",1);
}]]></xp:this.value>
                            </xp:selectItems>
                            <xp:eventHandler
                                event="onchange"
                                submit="false"
                            >
                                <xp:this.script><![CDATA[var curr = document.getElementById("#{id:comboBox2}").value;
var qc = document.getElementById("#{id:Currency}")
qc.value = curr]]></xp:this.script>
                            </xp:eventHandler>
                        </xp:comboBox>
                    </xe:formRow>
                    <xe:formRow
                        id="formRow2"
                        for="inputText2"
                        label="PSET:"
                    >
                        <xp:inputText
                            id="inputText2"
                            required="true"
                        >
                            <xp:this.validators>
                                <xp:validateRequired message="PSET is required"></xp:validateRequired>
                            </xp:this.validators>
                        </xp:inputText>
                    </xe:formRow>
                    <xe:formRow
                        id="formRow5"
                        label="Quoted Currency:"
                        rendered="false"
                        for="comboBox3"
                    >
                        <xp:comboBox id="comboBox3">
                            <xp:selectItem
                                itemLabel="* Select a Currency *"
                                itemValue=""
                            >
                            </xp:selectItem>
                            <xp:selectItems>
                                <xp:this.value><![CDATA[#{javascript:@DbColumn("","vCurrLookup",1);
}]]></xp:this.value>
                            </xp:selectItems>
                        </xp:comboBox>
                    </xe:formRow>
                </xe:formTable>
            </xe:dialogContent>
            <xe:dialogButtonBar id="dialogButtonBar1">
                <xp:panel>
                    <xp:button
                        value="Submit"
                        id="button4"
                    >
                        <i class="fa fa-large fa-fw fa-save"></i>
                        <xp:eventHandler
                            event="onclick"
                            submit="true"
                            refreshMode="partial"
                            refreshId="InstrumentDealPanel"
                        immediate="false" save="false">
                            <xp:this.action><![CDATA[#{javascript:sessionScope.SDR = null;
sessionScope.SDR = (sessionScope.SDR || new java.util.HashMap());
sessionScope.SDR.put("Form", compositeData.sdrForm);
sessionScope.SDR.put("PortfolioSystem", getComponentValue("PortfolioSystem"));
sessionScope.SDR.put("Request", "Y");
sessionScope.SDR.put("StaticRequested", "Yes");
sessionScope.SDR.put("Status",0);
sessionScope.SDR.put("StaticReqStatus", "New");
sessionScope.SDR.put("InstrumentType", compositeData.InstrumentType);
sessionScope.SDR.put("ISIN", getComponentValue("inputText1"));
sessionScope.SDR.put("Exchange", getComponentValue("comboBox1"));
sessionScope.SDR.put("Currency", getComponentValue("comboBox2"));
sessionScope.SDR.put("QuotationCurrency", getComponentValue("comboBox3"));
sessionScope.SDR.put("PSET", getComponentValue("inputText2"));
try {
    getComponent("ISIN").setValue(sessionScope.SDR.ISIN);
} catch(e) {}
try {
    getComponent("InstrumentShort").setValue("");
} catch(e) {}
try {
    getComponent("InstrumentName").setValue("");
} catch(e) {}
try {
    getComponent("RIC").setValue("");
} catch(e) {}
try {
    getComponent("CUSIP").setValue("");
} catch(e) {}
try {
    getComponent("SEDOL").setValue("");
} catch(e) {}
try {
    getComponent("BloombergID").setValue("");
} catch(e) {}
try {
    getComponent("MaturityDate").setValue("");
} catch(e) {}
try {
    getComponent("InstrumentType").setValue(sessionScope.SDR.InstrumentType);
} catch(e) {}
try {
    getComponent("Exchange").setValue(sessionScope.SDR.Exchange);
} catch(e) {}
try {
    getComponent("QuotationCurrency").setValue(sessionScope.SDR.QuotationCurrency);
} catch(e) {}
try {
    getComponent("Currency").setValue(sessionScope.SDR.Currency);
} catch(e) {}

try {
    getComponent("PSET").setValue(sessionScope.SDR.PSET);
} catch(e) {}
try {
    getComponent("PSETFull").setValue("");
} catch(e) {}

getComponent("dialogNewSec").hide();}]]></xp:this.action>
                        </xp:eventHandler>
                    </xp:button>
                    <xp:button
                        value="Cancel"
                        id="button5"
                    >
                        <i
                            class="fa fa-lg fa-fw fa-times"
                            style="color:red;"
                        >
                        </i>
                        <xp:eventHandler
                            event="onclick"
                            submit="false"
                        >
                            <xp:this.script><![CDATA[XSP.closeDialog('#{id:dialogNewSec}')]]></xp:this.script>
                        </xp:eventHandler>
                    </xp:button>
                </xp:panel>
            </xe:dialogButtonBar>
        </xe:dialog>

按钮显示对话框:

<xp:button
                    value="New Security..."
                    id="NewSecurityButton"
                    title="Create a new Security Request"
                >
                    <i
                        class="fa-external-link"
                    ></i>
                    <xp:this.rendered><![CDATA[#{javascript:@IsNewDoc() && compositeData.enableSDR && sessionScope.userRoles.contains("[STATICREQ]");}]]></xp:this.rendered>
                    <xp:eventHandler
                        event="onclick"
                        submit="false"
                        id="eventHandler4"
                    >
                        <xp:this.script><![CDATA[XSP.openDialog("#{id:dialogNewSec}");]]></xp:this.script>
                    </xp:eventHandler>
                </xp:button>

1 个答案:

答案 0 :(得分:2)

我认为问题是关闭面板的按钮的refreshId。 InstrumentDealPanel不在对话框中,因此在验证失败后,它会刷新该区域。它不会刷新对话框中的任何内容,因此对话框中的消息控件不会更新。

我认为InstrumentDealPanel是关闭对话框后要更新的面板。如果是,则该ID需要添加为getComponent("dialogNewSec").hide()的参数。

refreshId应该是对话框中包含错误控制的区域。它看起来根本不是样式控件,因此将其设置为messages1可能会有效。

如果您在应用程序中根本没有使用客户端验证,则可能更喜欢在“页面生成”选项卡上的Xsp属性文件中设置它,而不是在每个控件上设置它。