Wednesday, August 02, 2006

How to Access parameteters (request.getParameter) in JSF

How to Access parameteters in JSF -- request.getParameter()...

you cannot use #{request.getParameter("c"}. Such syntax is not acceptable.

From the Specification:
param—An immutable Map of the request parameters for this request, keyed by
parameter name. Only the first value for each parameter name is included.

So, #{param} are loaded from request Parameters by definition :-)

Just for testing purpose, put somewhere on your page to see what the #{param} contains.

You cannot use the session scope bean, because its properties cannot be initialized with the objects that have the shorter scope.


EXAMPLE 1
You can access your current request's instance in backing bean like :
String paramValue = ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter("paramName");


OR
EXAMPLE 2



OR
EXAMPLE 3
The easiest way to resolve this is to use a commandLink instead of a commandButton. Within your commandLink use f:param to send the subLink1 parameter:

Then in faces.config use the managed property and the implicit JSF expression variable "param" to set the parameter in your managed bean. Something like:

Then add a setter method in your managed bean for subLink1.



No comments: