Read query string using jsf, facelets and Seam-EL
If you are familiar with JavaServer Faces, maybe already read or heard someone talk about JSF implicit objects.
In short, an implicit object is similar to a managed bean, but one that is created and maintained by the JSF engine, which you may make reference to with EL.
The implicit EL object #{facesContext} maintained by the JSF servlet is instantiated from javax.faces.context.FacesContext, for each JSF request made upon the mid-tier. As the JSF lifecycle processes the current JSF request, the FacesContext instance carries the information about the page to be rendered, essentially the JSF response to the original request.
You can use this object to retrieve a reference to the request parameter map (which is a Map<String, String>) and through the JBoss-EL, access the value of the desired param.
Example:
GET request to: http://localhost:8080/yourApp/yourPage.seam?param1=value%201¶m2=1234
output: value 1
<h:outputText value=”#{facesContext.externalContext.requestParameterMap.get(‘param2′)}” />
output: 1234
Tip: there is also the #{param} implicit object. You can use this reference to grap your query string parameters in a short form as follows:
<h:outputText value=”#{param.get(‘parameterNameHere’)}” />
As you may be wondering, there are several other implicit objects. You can check them bellow.
- facesContext – The FacesContext instance for the current request.
- param – Maps a request parameter name to a single value.
- paramValues – Maps a request parameter name to an array of values.
- header – Maps a request header name to a single value.
- headerValues – Maps a request header name to an array of values.
- cookie – Maps a cookie name to a single cookie.
- initParam – Maps a context initialization parameter name to a single value.
Objects that allow access to various scoped variables:
- requestScope – Maps request-scoped variable names to their values.
- sessionScope – Maps session-scoped variable names to their values.
- applicationScope – Maps application-scoped variable names to their values.
When an expression references one of these objects by name, the appropriate object is returned. An implicit object takes precedence over an attribute that has the same name. For example, #{facesContext} returns the FacesContext object, even if there is an existing facesContext attribute containing some other value.
Github
Thank you.It helps me very well.