Ramanuj Singh
Ramanuj Singh

Reputation: 115

selectOneChoice is not able to cache the result in same task flow in oracle MAF

I have a task flow with two AMX pages. First page has a selectOneChoice (Product list) which is created from data control (having allProducts(a ArrayList of a ProductPOJO class)).

I dragged and drop allProducts from my dataControl to AMX page. and got code as-

<amx:selectOneChoice value="#{bindings.allProducts.inputValue}" label="Products" id="soc1"
                         valueChangeListener="#{pageFlowScope.lcBean.onProductChange}">
      <amx:selectItems value="#{bindings.allProducts.items}" id="si1"/>
    </amx:selectOneChoice>

and set a method onProductChange(ValueChangeEvent valueChangeEvent) inside a bean class where i am getting the selected row from selectOneChoice and doing further operation.

public void onProductChange(ValueChangeEvent valueChangeEvent) {
          AmxAttributeBinding productList =
              (AmxAttributeBinding) AdfmfJavaUtilities.evaluateELExpression("#{bindings.allProducts}");

          AmxIteratorBinding amxListIterator = productList.getIteratorBinding();

          BasicIterator basicIterator = amxListIterator.getIterator();

          ProductPOJO currentProduct = (ProductPOJO) basicIterator.getDataProvider();


          System.out.println("InSide onProductChange"+currentProduct.getProduct());

          ValueExpression ve;

          ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.nupMinimumsFlag}", Integer.class);
          ve.setValue(AdfmfJavaUtilities.getAdfELContext(), currentProduct.getNupMinimumsFlag());
          ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.productFlag}", Integer.class);
          ve.setValue(AdfmfJavaUtilities.getAdfELContext(), currentProduct.getProductFlag());
          ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.product}", String.class);
          ve.setValue(AdfmfJavaUtilities.getAdfELContext(), currentProduct.getProduct());

  }

Issue is :- when we select some value in selectOneChoice and then click on submit to go to next page. and then coming back to first page. Value of selectOneChoice is getting reset to default value(first value from collection). Its not able to cache the old(selected) value.

Upvotes: 1

Views: 316

Answers (1)

Ramanuj Singh
Ramanuj Singh

Reputation: 115

The working behaviour of select one choice is different on Oracle MAF. It is not able to cache the Object.

In first approach I was trying to cache an object.

To cache value on selectOneChoice we will have to get the index of selected choice and save it in your datacontrol class.

I got it fixed as below.

AMX Code :-

<amx:selectOneChoice value="#{bindings.selectedProduct.inputValue}"  label="Products" id="soc1"
                         valueChangeListener="#{bindings.onProductChange.execute}" required="true"
                         showRequired="true">
      <amx:selectItems value="#{bindings.allPoroducts.items}" id="si1"/>
    </amx:selectOneChoice>

Java Code :-

    public void onProductChange() {

    System.out.println("InSide onProductChange" + selectedProduct);

    ProductPOJO currentProduct = allPoroducts.get(Integer.parseInt(selectedProduct));

    System.out.println("InSide onProductChange" + currentProduct.getProduct());

    ValueExpression ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.nupMinimumsFlag}", Integer.class);
    ve.setValue(AdfmfJavaUtilities.getAdfELContext(), currentProduct.getNupMinimumsFlag());
    ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.productFlag}", Integer.class);
    ve.setValue(AdfmfJavaUtilities.getAdfELContext(), currentProduct.getProductFlag());
    ve = AdfmfJavaUtilities.getValueExpression("#{pageFlowScope.product}", String.class);
    ve.setValue(AdfmfJavaUtilities.getAdfELContext(), currentProduct.getProduct());

}

where 'private String selectedProduct;' is a string type object. so when we will select or change value on selectonechoice it will return numbers in string format like(0, 1, 2, 3, 4, 5 basically index values). which we will convert it to int and will get the value from product array with that index.

Upvotes: 1

Related Questions