This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am new to JSF, please can any one explain how am i suppose to populate/set some properties of components(based on some criteria) on first visit of page.
I have tried to use the PhaseListener, but when page is first visited ApplyRequest values does not occur.
The first thing that JSF does when asked to display a new page (View) is that the view is compiled and the "value=" expressions in the input and output controls are evaluated. Normally, those EL expressions reference properties in one or more backing beans, especially in the case of input controls. The backing bean's properties are queried to get the displayed values.
So you need to initialize the property values in the backing bean. If you do that, the display will automatically be initialized without the need to code any arcane JSF stuff - it's all POJO.
There are 2 ways to attack the particular case of setting data when a page loads. One is to invoke a setup routine in the backing bean from some other part of the application, which is a natural thing to do if the beans relate in some sort of workflow sequence. The other is to make the bean self-contained and add logic that is only called when the bean is first constructed or when the View is first requested. The @PostConstruct annotation can handle the case when you only want to initialize the bean once. Making a bean re-initialize itself on an "initial view" is trickier, but you can search this forum and find many discussions about that.
An IDE is no substitute for an Intelligent Developer.