JSF 1.2 Life Cycle understanding: Executing the ValueChangeListener #2

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.

JSF 1.2 Life Cycle understanding: Executing the ValueChangeListener method in InvokeApplication phase

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 }"/>

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>

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);

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


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.


TLDR: The fields are read-only

Whilst your panelGrid binds to loanBean which is mutable, the panelGrid is only using output components (subclasses of javax.faces.component.UIOutput) which are by definition read only. These do not have the methods which process request values (namely UIInput.setSubmittedValue, UIInput.getSubmittedValue and UIInput.setValue). In fact, when your form is submitted, the request includes no decoded values from the OutputText components.

For this reason, you do not need to play tricks during your ValueChangeListener process - it is safe to update the model values without worrying the the Apply Model Value phase will overwrite.

UIInput Javadoc: http://docs.oracle.com/cd/E17802_01/j2ee/j2ee/javaserverfaces/1.2/docs/api/javax/faces/component/UIInput.html

Debugging phases: http://www.ibm.com/developerworks/java/tutorials/j-jsf2/section7.html

Need Your Help

Comparing Files dependent on operative system. JUnit

java csv junit operating-system

I have a simple JUnit test which checks two files have the same content. It works perfectly fine in my Unix laptop.

Bundle Does Not Exist: Symfony2

symfony2 controller bundle

I'm pretty new to Symfony2. I can't figure out what's going on. This code (set up to test if the bundle can be detected):

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.