0

私は ADF を初めて使用し、いくつかの問題に直面af:selectOneChoiceしています。ページにデータのリストを含むコンポーネントがあります。

selectOnceChoiceユーザーがコンポーネントのリストから 1 つのオプションを選択したときに、選択した値を取得したいと考えています。

リクエスト Bean をパラメータで使用し、それをコンポーネントのプロパティ インスペクタの値オプションにバインドしましたが、選択した値を与えることができませんでした。selectOneChoiceコンポーネントから選択した値を取得するにはどうすればよいですか?

4

5 に答える 5

3

ValueChangeListenerコンポーネントを使用できselectOnceChoiceます。これを Bean クラス メソッドにバインドし、API を呼び出して、コンポーネントvalueChangeListenerの新しい値または古い値を取得できます。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>
于 2011-09-12T08:29:22.343 に答える
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から

于 2012-02-06T17:58:44.290 に答える
0

autoSubmit プロパティを「true」に使用する場合は、immediate プロパティも「true」に設定してください。それ以外の場合、検証はページ レベルで実行されます。

于 2012-12-16T11:33:03.597 に答える
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();  
}
于 2012-12-14T18:20:50.447 に答える
0

私がそれを正しければ、あなたの問題はその値であり、あなたが選択したものaf:selectOneChoiceは、提出後にのみBeanで利用可能になります。その場合は、ユーザーにフォームを送信させるか、autoSubmitコンポーネントのプロパティを に設定する必要がありますtrue

于 2012-08-11T02:36:35.880 に答える