【问题标题】:selectOneChoice populate with pre-selected default valueselectOneChoice 填充预选的默认值
【发布时间】:2015-04-15 10:07:59
【问题描述】:

我需要 af:selectOneChoice 填充来自支持 bean 的值,并且默认情况下应该选择列表中的一个值(比如 index=5)。我们正在使用 Oracle Adf 10。*

有人可以帮我吗?

谢谢

【问题讨论】:

    标签: oracle-adf


    【解决方案1】:

    要填充列表值,您可以使用:

    <af:selectOneChoice value="val3" label="XXXX" id="soc1" >
          <f:selectItems value="#{YourBean.values}" id="si1"/>
    </af:selectOneChoice>
    

    在 YourBean.java 中,您将有一个类似的方法:

    public List<SelectItem> getValues() {
       if (list == null) {
                list = new ArrayList<SelectItem>();
                list(new SelectItem("val1","Label 1"));
                list(new SelectItem("val2","Label 2"));
                list(new SelectItem("val3","Label 3"));
    
       }
       return list;
    

    }

    这样您将在选择列表中看到“标签 3”作为默认值。

    【讨论】:

    • 弗洛林,感谢 cmets
    • 当我移动 value="#{backBean.dynamicValue}" 时发生了奇怪的事情。在上面的场景中,屏幕已经填充了作为标签而不是下拉列表的选定值。但是如果应用字符串 (value="blah") 那么它会完美地填充和选择。有什么想法吗?
    • 您的支持 bean 中有 getDynamicValue() 方法吗?读取“#{backBean.dynamicValue}”EL时需要
    • 是的,我有。 selectOneChoice>
    • Marcus,当我更改支持的 bean 返回 CoreInputText 而不是字符串时,它的工作原理。
    【解决方案2】:

    要设置默认值,你可以这样:

    <af:selectOneChoice label="My Field"
                        id="MyField" value="#{bindings.MyAttribute.inputValue}"
                        autoSubmit="true"
                        binding="#{MyBean.myField}">
      <f:selectItems value="#{bindings.MyAttribute.items}"
                     id="MyFieldItems"/>
    </af:selectOneChoice>
    

    请注意,SelectOneChoice 字段绑定到一个 java bean。我们将使用 setter 方法来设置默认值。

    public void setMyField(RichSelectOneChoice myField) {
        // since getter/setter methods are called multiple times on
        // page load, we need to prevent setting attribute value more than once
        if(myField != null && myField.getValue() == null){
            ADFUtils.setBoundAttributeValue("MyAttribute", "SomeValue");
        }
        this.myField = myField;
    }
    

    对于设置默认索引(例如,列表中的第一个)我们可以使用类似的方法:

    public void setMyField(RichSelectOneChoice myField) {
        if(myField != null && myField.getValue() == null){
            // default value will be 1st from the list
            myField.setValue(0);
        }
        this.myField = myField;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      相关资源
      最近更新 更多