This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Welcome to the JavaRanch. We're a laid-back bunch and don't have many rules, but we really do prefer that you use a display name that has a first name and a last name and, preferably is your real name, just like you'd use it in professional correspondence. Could you change it please? Thanks.
As for your question, JSF makes itself look a little more like a traditional client/server app and less like a request/response app than other frameworks such as Struts do, so "loading a page" is a little hard to discuss (for me, anyway). Probably the closest I could come is to suggest you look at how JSF renderkits work.
Customer surveys are for companies who didn't pay proper attention to begin with.
I want to call a private method on load of a jsp page which uses a few objects which can be accessed by the jsp page only. So i will need a PhaseListener for the page. Without using viewId can i make a phaseListener for a specific page.
One solution that can be thought of is:
There is no init method which is executed everytime and before the JSP page loads.
All the fields declared on the jsp page happen to be execute sequentially. To simulate the onLoad method. Perform the following.
1. Under the <h:form> tag, declare a hidden variable
[Explanation: As soon as you mention the property name in the value attribute, the getter of that property from the backing bean will be called]
2. In the getter method of the property call the method which you want to call onLoad of the jsp page or write the entire code which you want to execute in the onLoad method.
This is the simplest method i could think of.
I have heard of PhaseListener on most of the forums, however i am not bale to implement it, if you could do so.. or for that matter anybody having any knowledge about this
Joined: Sep 16, 2005
Have you considered overriding the jspInit metod of your page?
Yet another trick is to create a binding to a backing bean.
setInit() will now get called at each page load. I think this is a little less of a hack than the hidden input is. (caveat you MUST also supply the getter for init even though it won't be used)
I'm also not really sure if I agree with the comment given above that page loads are something you don't want to think about. Maybe you don't want to think about them as explicit page loads, but you do want some notion of a pre-render event for the whole interface. ASP.NET looks very much like JSF and it does have this concept.
Also, if you're dealing with session scoped backing beans and need to process get parameters then there's no other way. You need some onPageLoad mechanism. Now some people would say get parameters don't belong in a JSF application. The matter of the fact is however that people wish to link to pages from external sources and when that happens there's just no way around using get parameters.