This is my first post about Oracle ADF technology. First of all, I have to explain why after this post will be many others. A few months ago, I changed for work to Oracle Corp. For that reason, It’s normal that I’ll see products and technologies from this company.
Today’s post I will talk about how to adding a parameter to ValueChangeListener event from JSF. In fact, I didn’t find a nice way to do this. So, the reason for I’m writing this post is also share my knowledge and find other way to do the same thing.
My issue was: I have a beauty datatable built using af:table. This table has a column with a af:selectOneChoice, because the user can choose in a dropdown which value is better for him. Simple and clean. When the User change this value, I have to show a friendly message, based on the value from another column in the same row. Therefore, I would like to have in my backing bean this row selected or this specific other column value to my purpose.
The unique option that I found is using ValueChangeListener and navigate to the components in runtime. I will explain with the code.
That’s my af:column:
<af:column width="10%" align="center" sortable="false" headerText="Regular (%)" id="c9">
<af:inputText id="limiteMaximo" <strong>visible="false"</strong> value="#{row.limitesContribuicaoPP2.limiteMaximo}">
<f:convertNumber />
</af:inputText>
<af:selectOneChoice autoSubmit="true"
value="#{row.limitesContribuicaoPP2.percentualRegularToString}"
id="comboRegular" valuePassThru="true"
valueChangeListener="#{Petros2MB.onChangePercentualRegular}">
<f:selectItems value="#{row.percentuaisRegular}" id="si4"/>
</af:selectOneChoice>
</af:column>
There are two components inside the column: af:inputText and af:selectOneChoice. The trick is, the component inputText is not visible (the old h:inputHidden), I prefer put in this way, just to simplify my managed bean. In the valueChangeListener method I can get this value in inputText and make my decision. Let’s go to the MB code:
public void onChangePercentualRegular(ValueChangeEvent evt){
if (evt.getNewValue() != null){
String strNewValue = (String)evt.getNewValue();
Integer newValue = Integer.parseInt(strNewValue);
RichColumn column = (RichColumn)evt.getComponent().getParent();
RichInputText inputLimiteMaximo = (RichInputText)column.getChildren().get(0);
Integer limiteMaximo = (Integer)inputLimiteMaximo.getValue();
if (newValue < limiteMaximo){//process what i want to do}
}
}
In fact, I woudn’t need to put the component inputText visible=false inside my column, but I prefer in that way for simplify my MB code. I can navigate for all components in this page, just using getParent and getChildren. However, It’s not a good tip, because If you need to change something in the page, probably this could affect in your MB. So, be careful!