选择一个选项,用预先选择的默认值填充。

问题描述 投票:0回答:2

我需要af:selectOneChoice用来自backing bean的值填充,并且从列表中选择一个值(比如index=5)作为默认值。我们使用的是Oracle Adf 10.*。

谁能帮我解决这个问题?

谢谢你的帮助

oracle-adf
2个回答
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 "为默认值。


0
投票

对于设置默认值,你可以使用这个。

<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;
}
© www.soinside.com 2019 - 2024. All rights reserved.