ADF中的selectOneChoice

时间:2011-08-25 10:56:26

标签: jdeveloper oracle-adf

我是ADF的新手,面临一些问题:我的页面中有一个af:selectOneChoice组件,其中包含一个数据列表。

当用户从selectOnceChoice组件列表中选择一个选项时,我想获取所选值。

我已经将request bean与参数一起使用,并将其绑定在组件的属性检查器的value选项中,但它未能提供所选的值。如何从selectOneChoice组件中获取所选值?

5 个答案:

答案 0 :(得分:3)

您可以使用ValueChangeListenerselectOnceChoice组件。在valueChangeListener中,您可以将其绑定到bean类方法并调用API以获取selectOnceChoice组件的新值或旧值:

public void selectOnceChoiceValue(ValueChangeEvent valueChangeEvent){
    if(valueChangeEvent != null) {
        Object newVal = valueChangeEvent.getNewValue();
        Object oldVal = valueChangeEvent.getOldValue();
    }
}
<af:selectOneChoice id="soc1" simple="true" autoSubmit="true"
   valueChangeListener="#{ExtnEmailNotificationPFBean.recipientTypeValue}"
   label="#{''}"
   binding="#{ExtnEmailNotificationPFBean.recipientTypeValue}"
   partialTriggers="cl2"
   value="#{pageFlowScope.ZcxEaNotificationRecipientType}">
  <f:selectItems id="si4"
          value="#{pageFlowScope.ZcxEaRecipientsTypeValueList}"/>                  
</af:selectOneChoice>

答案 1 :(得分:1)

根据您需要对值执行的操作,一个选项是支持bean中的以下方法

public void valueChanged(ValueChangeEvent valueChangeEvent) {
    this.setValueToEL("#{bindings.Deptno.inputValue}", valueChangeEvent.getNewValue()); //Updates the model
    System.out.println("\n******** Selected Value: "+resolveExpression("#{bindings.Deptno.attributeValue}"));
    System.out.println("\n******** Display Value: "+resolveExpression("#{bindings.Deptno.selectedValue ne ' ' ? bindings.Deptno.selectedValue.attributeValues[1] : ''}"));
}

public Object resolveExpression(String el) {      
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory expressionFactory =  facesContext.getApplication().getExpressionFactory();        
    ValueExpression valueExp = expressionFactory.createValueExpression(elContext,el,Object.class);
return valueExp.getValue(elContext);
}

public void setValueToEL(String el, Object val) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory expressionFactory =   facesContext.getApplication().getExpressionFactory();
    ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);
    exp.setValue(elContext, val);
}

你的JSP组件应该看起来像

<af:selectOneChoice value="#{bindings.Deptno.inputValue}" label="Select Department"
                            required="true" shortDesc="#{bindings.Deptno.hints.tooltip}"
                            id="soc1" autoSubmit="true">
          <f:selectItems value="#{bindings.Deptno.items}" id="si1"/>
</af:selectOneChoice>

来自http://blogs.oracle.com/adf/entry/getting_selected_value_from_selectonechoice

如果您正在查看与支持组件的视图对象的连接,那么这将实时显示您显示的文本。

public void buttonPressed(ActionEvent actionEvent) {

    // Get the binding
    BindingContainer bindings =
    BindingContext.getCurrent().getCurrentBindingsEntry();
    // Get the sepecific list binding
    JUCtrlListBinding listBinding =
    (JUCtrlListBinding)bindings.get("DepartmentId");
    // Get the value which is currently selected
    Object selectedValue = listBinding.getSelectedValue();
    System.out.println(selectedValue);
}

来自http://blogs.oracle.com/shay/entry/getting_the_value_from_a_selec

答案 2 :(得分:0)

如果我做对了,你的问题就是那个用af:selectOneChoice选择的值只有在提交后才可以在bean上使用。如果是这种情况,那么您应该让用户提交表单,或者将组件的autoSubmit属性设置为true

答案 3 :(得分:0)

这应该做:

<af:selectOneChoice id="sampleId" 
value="#{bindings.sampleAttribute.inputValue}"
label="#{bindings.sampleAttribute.label}"
valueChangeListener=#"{Bean.valueChangeListener}"
immediate="true" autoSubmit="true">
    <f:selectItems id="sampleAttributeValues"
    value="#{bindings.sampleAttribute.items}"/>
</af:selectOneChoice>

并且bean将具有:

public void valueChangeListener(ValueChangeEvent valueChangeEvent)
{
    FacesContext.getCurrentInstance().renderResponse();  
}

答案 4 :(得分:0)

如果您将autoSubmit属性用于“true”,请确保将immediate设置为“true”。否则,将在页面级别触发验证。