1

我在具有相同 groupName 的表中有单选按钮。是否有一种相对简单的方法可以在不使用 CCJS 的情况下在提交表单时验证此字段?

<xp:td>
    <xp:radio id="radio120" groupName="R_1" value="#{document1.R_1}" selectedValue="1"></xp:radio>
</xp:td>
<xp:td>
    <xp:radio id="radio120" groupName="R_1" value="#{document1.R_1}" selectedValue="2"></xp:radio>
</xp:td>

对于常规单选按钮组控件,我使用 validateRequired 和 errorMessage 控件来显示消息。

<xp:radioGroup styleClass="A2" style="border:0px;" value="#{document1.Necktie}" layout="pageDirection" id="Necktie">
    <xp:this.validators>
        <xp:validateRequired message="REQUIRED!"></xp:validateRequired>
    </xp:this.validators>
    <xp:selectItem itemLabel="No" id="selectItem13"></xp:selectItem>
    <xp:selectItem itemLabel="Yes" id="selectItem14"></xp:selectItem>
</xp:radioGroup>
<xp:message id="message10" for="Necktie"></xp:message>
4

2 回答 2

0

很公平......在那种情况下,除了用 CSJS 做一些事情之外,我不太确定......

不确定这是否会有所帮助,但请看一下 Marky Roden 的这篇文章: https ://xomino.com/2012/03/10/checking-xpages-radio-buttons-have-been-selected-with- jQuery/

随着年底的到来,我已经有 4/5 周没有做任何开发工作了,所以我的大脑并没有像它应该的那样工作.....

于 2016-11-30T16:22:39.197 回答
0

使用服务器端的数据源 document1 来确定您的单选按钮是否被选中。
测试document1.getItemValueString("R_1"). 如果为空,则设置错误消息并返回 false。否则保存文档。

<xp:button value="Save" id="button1">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
        <xp:this.action><![CDATA[#{javascript:
            if (document1.getItemValueString("R_1") == "") {
                facesContext.addMessage(null, 
                    new javax.faces.application.FacesMessage("select a radio"));
                return false;
            }
            document1.save();
        }]]></xp:this.action>
    </xp:eventHandler>
</xp:button>
<xp:messages id="messages1" />
于 2016-12-02T12:25:52.563 回答