Wanna Coffee
Wanna Coffee

Reputation: 2798

Oracle MAF : Reflect value into inputText based on multiple selectOneChoice selection

I have created three selectOneChoice component in calc.amx, based on the value changes it will do calculation and result you some output. I need to append it to same amx page as a inputText (non-editable text). Below are the my try,


Calc.amx:

All this selectOneChoice will have valueChangeListener to set value into bean,

<amx:selectOneChoice value="valueOne" label="Value One" id="soc1" valueChangeListener="#{calcBean.setValueOne}">
    <amx:selectItems value="valueOne" id="si1"/>
</amx:selectOneChoice>

<amx:selectOneChoice value="valueTwo" label="Value Two" id="soc2" valueChangeListener="#{calcBean.setValueTwo}">
    <amx:selectItems value="valueTwo" id="si2"/>
</amx:selectOneChoice>

<amx:selectOneChoice value="valueThree" label="Value Three" id="soc3" valueChangeListener="#{calcBean.setValueThree}">
    <amx:selectItems value="valueThree" id="si3"/>
</amx:selectOneChoice>
<amx:inputText value="#{bindings.grantTotal.inputValue}" label="#{bindings.grantTotal.hints.label}" id="it4"/>

CalcBean.java:

private String firstValue;
private String secondValue;
private String thirdValue;
private String grantTotal;


public void setFirstValue(String firstValue) {
    String oldFirstValue = this.firstValue;
    this.firstValue = firstValue;
    propertyChangeSupport.firePropertyChange("firstValue", oldFirstValue, firstValue);
}

public String getFirstValue() {
    return firstValue;
}

public void setSecondValue(String secondValue) {
    String oldSecondValue = this.secondValue;
    this.secondValue = secondValue;
    propertyChangeSupport.firePropertyChange("secondValue", oldSecondValue, secondValue);
}

public String getSecondValue() {
    return secondValue;
}

public void setThirdValue(String thirdValue) {
    String oldThirdValue = this.thirdValue;
    this.thirdValue = thirdValue;
    propertyChangeSupport.firePropertyChange("thirdValue", oldThirdValue, thirdValue);
}

public String getThirdValue() {
    return thirdValue;
}

public void setGrantTotal(String grantTotal) {
    String oldGrantTotal = this.grantTotal;
    this.grantTotal = grantTotal;
    propertyChangeSupport.firePropertyChange("grantTotal", oldGrantTotal, grantTotal);
}

public String getGrantTotal() {
    return grantTotal;
}


public void addPropertyChangeListener(PropertyChangeListener l) {
    propertyChangeSupport.addPropertyChangeListener(l);
}

public void removePropertyChangeListener(PropertyChangeListener l) {
    propertyChangeSupport.removePropertyChangeListener(l);
}

public void setValueOne(ValueChangeEvent valueChangeEvent) {
    firstValue = valueChangeEvent.getNewValue().toString();
    doCalc(firstValue,secondValue,thirdValue);
}

public void setValueTwo(ValueChangeEvent valueChangeEvent) {
    secondValue = valueChangeEvent.getNewValue().toString();
    doCalc(firstValue,secondValue,thirdValue);
}

public void setValueThree(ValueChangeEvent valueChangeEvent) {
    thirdValue = valueChangeEvent.getNewValue().toString();
    doCalc(firstValue,secondValue,thirdValue);
}

public void doCalc(String firstValue, String secondValue, String thirdValue){
    if(firstValue!=null&&secondValue!=null&&thirdValue!=null){
        System.out.println(firstValue+secondValue+thirdValue);
        grantTotal = firstValue+secondValue+thirdValue;
        setGrantTotal(grantTotal);
        System.out.println("grantTotal : "+grantTotal);
    } else {
        grantTotal = "No Value";
        setGrantTotal(grantTotal);
        System.out.println("grantTotal : "+grantTotal);
    }

}

So I'm able to do the calculation based on the selectOneChoice selection and also able to print the calculated output in sop statement.

Now, how I can reflect the grantTotal value into same amx page in inputText based on every selectOneChoice selection?

Upvotes: 3

Views: 945

Answers (1)

User404
User404

Reputation: 2192

Is the grandTotal an attributeValue in your bindings? If so, you can easily set the value using EL.


Example:

 int myValue = 123; 
 AdfmfJavaUtilities.setELValue("#{bindings.GrandTotal.inputValue}", myValue); 

Click Here for Oracle documentation regarding setELValue().

Upvotes: 3

Related Questions