[OmniFaces utilities] The
contains()
function returns true
if the string representation of an item of the given array equals to the string representation of the given item. This returns false
if either the array or the item is null
. This is useful if you want to for example check if #{paramValues.foo}
contains a certain value.Function:
Usage:
The of:contains()
function is useful to check if the header values map (available via #{headerValues}
implicit object) or the request parameters map (available via #{paramValues}
implicit object) contains a certain value. For example, you can easily check if
the current host is your localhost address, like this (e.g. localhost:8080):
// This will
be evaluated to true
for a request as: http://localhost:8080/Myapp/...
#{of:contains(headerValues['Host'],
'localhost:8080')}
Or, you can
check a certain value for a query request parameter:
// suppose
we have these two URLs:
http://localhost:8080/
Myapp /?user=guest
#{of:contains(paramValues['user'],
'guest')} // return true
http://localhost:8080/
Myapp /?user=admin
#{of:contains(paramValues['user'],
'guest')} // return false
// or these
two URLs
http://localhost:8080/MyApp/?product=ties&product=jeans&product=shoes&product=hats
#{of:contains(paramValues['product'],
'shoes')} // return true
http://localhost:8080/MyApp/?product=ties&product=jeans&product=hats
#{of:contains(paramValues['product'],
'shoes')} // return false
Or, you can
check a certain value for a request parameter:
<h:form
id="registerId">
<h:inputText id="nameId"/>
<h:commandButton
value="Register"/>
</h:form>
// check if
the user submitted, Buzz
#{of:contains(paramValues['registerId:nameId'],
'Buzz')}
Niciun comentariu :
Trimiteți un comentariu