[OmniFaces utilities] The
getRequestParameterMap()
method returns the HTTP request parameter map.[OmniFaces utilities] The
getRequestParameter()
method returns the HTTP request parameter value associated with the given name.[OmniFaces utilities] The
getRequestParameterValuesMap()
method returns the HTTP request parameter values map.[OmniFaces utilities] The
getRequestParameterValues()
method returns the HTTP request parameter values associated with the given name.Method Faces#getRequestParameterMap() - returns the HTTP request parameter map:
See also: Faces#getContext()
Method Faces#getRequestParameter()- returns the HTTP request parameter value associated with the given name:
See also: Faces#getContext()
Method Faces#getRequestParameterValuesMap() - returns the HTTP request parameter values map:
See also: Faces#getContext()
Method Faces#getRequestParameterValues() - returns the
HTTP request parameter values associated with the given name.
See also: Faces#getContext()
Usage:
Let's
suppose a simple form, as below (the typed e-mail is rafa@rg.com; the typed
password is rafa2015):
<h:form
id="loginFormId">
E-mail: <h:inputText id="emailId"
required="true" value="#{loginBean.email}"/>
Password: <h:inputSecret
id="passwordId" required="true"
value="#{loginBean.password}"/>
<h:commandButton id="submitId"
value="Login" action="#{loginBean.loginAction()}">
<o:param name="name"
value="Rafael"/>
<o:param name="surname"
value="Nadal"/>
</h:commandButton>
</h:form>
The HTTP
request parameter map can be accessed via Faces#getRequestParameterMap(),
as below:
import
org.omnifaces.util.Faces;
...
Map<String, String>
requestParameterMap = Faces.getRequestParameterMap();
for
(Map.Entry<String, String> entry : requestParameterMap.entrySet()) {
System.out.println(entry.getKey() +
"/" + entry.getValue());
//
do something with request parameters
}
For example,
a possible output can be:
loginFormId/loginFormId
loginFormId:emailId/rafa@rg.com
loginFormId:passwordId/rafa2015
javax.faces.ViewState/-6143882821103406077:2092678555969042270
submitId/submitId
name/Rafael
surname/Nadal
If you need
only the value of a single parameter then you can use Faces#getRequestParameter().
For example, let's suppose that we are interested only in the loginFormId:passwordId
parameter value. Then we write this:
import
org.omnifaces.util.Faces;
...
// the 'passwordValue'
will be 'rafa2015'
String passwordValue =
Faces.getRequestParameter("loginFormId:passwordId");
If you need the
"immutable Map
whose keys are the set of request parameters names included in the current
request, and whose values (of type String[]) are all of the values for each
parameter name returned by the underlying request - Mojarra documentation",
then you can use Faces#getRequestParameterValuesMap(), as below:
import
org.omnifaces.util.Faces;
...
Map<String, String[]>
requestParameterValuesMap = Faces.getRequestParameterValuesMap();
for
(Map.Entry<String, String[]> entry :
requestParameterValuesMap.entrySet()) {
System.out.println(entry.getKey() +
"/" + Arrays.toString(entry.getValue()));
//
do something with request parameters
}
For example,
a possible output can be:
loginFormId/[loginFormId]
loginFormId:emailId/[rafa@rg.com]
loginFormId:passwordId/[pass2015]
javax.faces.ViewState/[4106157608838210808:-906773219723375164]
submitId/[submitId]
name/[Rafael]
surname/[Nadal
If you need
to returns the HTTP request parameter values associated with the given name,
then you can use Faces#getRequestParameterValues(). Let's try the
same loginFormId:passwordId parameter
value (in this case, is a single value):
import
org.omnifaces.util.Faces;
...
// the 'passwordValues'
array will contain only 'rafa2015' value
String[] passwordValues =
Faces.getRequestParameterValues("loginFormId:passwordId");
More details
about request parameters in "JSF 2.2 - <h:form> and request/viewparameters".
Niciun comentariu :
Trimiteți un comentariu