通过 groupName 验证 Xpages 单选按钮?

Xpages radio button validation by groupName?

我在 table 中有一个具有相同组名的单选按钮。 有没有一种相对简单的方法可以在不使用 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>

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

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

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

使用服务器端的数据源 document1 查看是否选择了您的单选按钮。
测试 document1.getItemValueString("R_1")。如果它为空,则设置错误消息和 return 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" />