锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
2.Call FacesContext.renderResponse() to skip the rest of the life cycle up to Render Response.
3.Call FacesContext.responseComplete() to skip the rest of the life cycle entirely.
See "Immediate Components" on page 287 for an example of using FacesContext.renderResponse().
The call to renderResponse() skips the rest of the life cycle鈥攊ncluding validation of the rest of the input components in the form鈥攗p to Render Response. Thus, the other validations are skipped and the response is rendered normally (in this case, the current page is redisplayed).
To summarize, you can skip validation when a value change event fires by doing the following:
Adding an immediate attribute to your input tag
Calling FacesContext.renderResponse() at the end of your listener
Variable Name | Meaning |
---|---|
header | A Map of HTTP header parameters, containing only the first value for each name. |
headerValues | A Map of HTTP header parameters, yielding a String[]array of all values for a given name. |
param | A Map of HTTP request parameters, containing only the first value for each name. |
paramValues | A Map of HTTP request parameters, yielding a String[]array of all values for a given name. |
cookie | A Map of the cookie names and values of the current request. |
initParam | A Map of the initialization parameters of this web application. Initialization parameters are discussed in Chapter 10. |
requestScope | A Map of all request scope attributes. |
sessionScope | A Map of all session scope attributes. |
applicationScope | A Map of all application scope attributes. |
facesContext | The FacesContext instance of this request. This class is discussed in Chapter 6. |
view | The UIViewRoot instance of this request. This class is discussed in |
Finally, if the name is still not found, it is passed to the VariableResolver of the JSF application. The default variable resolver looks up managed-bean elements in a configuration resource, typically the faces-config.xml file.
Consider, for example, the expression
#{user.password}
The term user is not one of the predefined(棰勫畾涔? objects. When it is encountered錛堥亣鍒幫級 for the first time, it is not an attribute name in request, session, or application scope.
Therefore, the variable resolver processes the faces-config.xml entry:
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.corejsf.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
The variable resolver calls the default constructor of the class com.corejsf.User-Bean. Next, it adds an association to the sessionScope map. Finally, it returns the object as the result of the lookup.
When the term user needs to be resolved again in the same session, it is located in the session scope
Composite Expressions
You can use a limited set of operators inside value expressions:
Arithmetic operators + - * / %. The last two operators have alphabetic variants div and mod.
Relational operators < <= > >= == != and their alphabetic variants lt le gt ge eq ne. The first four variants are required for XML safety.
Logical operators && || ! and their alphabetic variants and or not. The first variant is required for XML safety.
The empty operator. The expression empty a is true if a is null, an array or String of length 0, or a Collection or Map of size 0.
The ternary ?: selection operator.
Operator precedence follows the same rules as in Java. The empty operator has the same precedence as the unary - and ! operators.
Generally, you do not want to do a lot of expression computation in web pages鈥攖hat would violate the separation of presentation and business logic. However, occasionally, the presentation layer can benefit from operators. For example, suppose you want to hide a component when the hide property of a bean is true. To hide a component, you set its rendered attribute to false. Inverting the bean value requires the ! (or not) operator:
<h:inputText rendered="#{!bean.hide}" ... />
Finally, you can concatenate plain strings and value expressions by placing them next to each other. Consider, for example,
<h:outputText value="#{messages.greeting}, #{user.name}!"/>
The statement concatenates four strings: the string returned from #{messages. greeting}, the string consisting of a comma and a space, the string returned from #{user.name}, and the string consisting of an exclamation mark.
涓婃枃鍑鴻嚜錛氥奵ore JavaServer™ Faces, Second Edition銆?/span>
For example, suppose that in our quiz application, the startOverAction returns the string "again" instead of "startOver". The same string can be returned by the answerAction. To differentiate between the two navigation cases, you can use a from-action element. The contents of the element must be identical to the method expression string of the action attribute:
This rule applies to all pages that start with the prefix /secure/. Only a single * is allowed, and it must be at the end of the ID string.
涓婃枃鍑鴻嚜錛氥奵ore JavaServer™ Faces, Second Edition銆?/span>(This mechanism is attractive for builder tools because it separates navigation, beans, etc.)
Redirecting the page is slower than forwarding because another round trip to the browser is involved. However, the redirection gives the browser a chance to update its address field.
Figure 3-8 shows how the address field changes when you add a redirection element, as follows:
Without redirection, the original URL (localhost:8080/javaquiz/index.faces) is unchanged when the user moves from the /index.jsp page to the /success.jsp face. With redirection, the browser displays the new URL (localhost:8080/ javaquiz/success.faces).
Tip
![]() |
Use the redirect element for pages that the user might want to bookmark. |