有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Primefaces SelectOneRadio,选择了NoSelection选项

如何使selectOneRadio具有默认选中的NoSelection选项

我有以下资料:

<p:selectOneRadio>
    <f:selectItem itemLabel="none" noSelectionOption="true"/>
    <f:selectItems value="#{bean.anything}"/>
</p:selectOneRadio>

我想在默认情况下选择“无”?我该怎么做?因为没有“选定”的属性


共 (1) 个答案

  1. # 1 楼答案

    使用绑定到视图的托管bean字段,其值为null,还可以使用未选择的选项,其值为null

    JSF部分:

    <p:selectOneRadio value="#{bean.foo}">
        <f:selectItem itemLabel="none" itemValue="#{null}" noSelectionOption="true"/>
        <f:selectItems value="#{bean.anything}"/>
    </p:selectOneRadio>
    

    托管bean代码:

    @ManagedBean
    @RequestScoped
    public class Bean {
        //its value by default will be null
        private String foo;
        //getters and setters...
    }