I am using JSF framework and my requirement is to hit a URL e.g http://localhost/jsfApp/us?param1=name¶m2=pass.
Now I want to make a database call and fetch some data based on param1 & param2 even before any .jsp is displayed.
So is there any way to link the URL to any Bean/Java file where I could write the code for DB call, the result of which I will store in a ArrayList in the bean which will eventually be displayed on the .jsp file.
Thanks,
Narain
Make
param1andparam2managed properties so that JSF will set them during bean’s construction.(or if you’re still on JSF 1.x, then you need to declare them as
<managed-property>infaces-config.xmlfile instead)Then you can do the DB retrieval job in a postconstruct method which will be invoked directly after bean’s construction and all managed property setting.
(or if you’re still on JSF 1.1 or older, then you need to upgrade to at least JSF 1.2 or better JSF 2.x)
Finally just reference the result in the view.
An alternative to
@ManagedPropertyin JSF 2.0 is the<f:metadata>in the view.This allows for more fine-grained control of validation and conversion of them.