I am using JSF v1.2 for my application. This is a sort-of-similar question to this thread (answered by BalusC) which I marked as answered some days back.
No dataTable
this time, only a form with a dropdown
and a panelgrid
containing some outputText
. Based on the dropdown
value selected by the user, some outputText
fields present inside the panelGrid
have to be populated.
Below is the code for the drop-down:
<h:selectOneMenu id="drpDownLoans" value="#{loanBean.loanId }" valueChangeListener="#{loanBean.getLoanDetails }" onchange="submit()">
<f:selectItem itemLabel="--Select--" itemValue="0"/>
<f:selectItems value="#{loanBean.availableLoans }"/>
</h:selectOneMenu>
On changing the drop-down value; I want to populate some outputText
from the DB, below is the code:
<h:panelGrid columns="2">
<h:outputLabel id="lblLoanId" value="Loan Id"></h:outputLabel>
<h:outputText id="txtLoanId" value="#{loanBean.loanId }"></h:outputText>
<h:outputLabel id="lblROI" value="Rate of Interest (% pa)"></h:outputLabel>
<h:outputText id="txtROI" value="#{loanBean.rateOfInterest }"></h:outputText>
<h:outputLabel id="lblNOI" value="No. of Installments (months))"></h:outputLabel>
<h:outputText id="txtNOI" value="#{loanBean.noOfInstallments }"></h:outputText>
</h:panelGrid>
Below is the code executed at the LoanBean.java:
public void getLoanDetails(ValueChangeEvent event){
Integer value = (Integer)event.getNewValue();
DataService service = new DataService();
LoanBean loanBean = service.getLoanDetails(value);
this.setLoanId(loanBean.getLoanId());
this.setRateOfInterest(loanBean.getRateOfInterest());
this.setNoOfInstallments(loanBean.getNoOfInstallments());
}
The code is working perfectly but don't know WHY :(
My understanding: Default values for Integer i.e. 0 and String i.e. null should be displayed
WHY
Both the dropdown
and the outputText
are present in the form
element. When the form is submitted on drop-down value change, then the values of the fields present in the panelGrid
are set to default i.e. for integer
, the component#submittedValue will be 0
and for String
it will be null
. Since I dont have any Converter/Validator, the component#Value will also be 0
for integer
and null
for String
. Then ValueChangeEvent
will be executed and all the values are set to the panelGrid
contents based on the values fetched from the DB. Then in phase 4, all these values set in phase 3 by the db hit should be reset to their default values based on the component#value which is set after the Convertor/Validator hence it should be 0
for integer
and null
for String
. Then why are the values getting populated correctly rather than default values?
Yet again stuck conceptually on the life cycle events :( Please pin-ponit what I am missing in my mis-understanding.