JSF: initial request and postback request?
Please take a look at this below line of code in JSF
<h:inputText id="name" value="#{customer.name}" />
Quote from java.sun.com:
For an initial request of the page containing this tag, the JavaServer Faces implementation evaluates the
#{customer.name}
expression during the render response phase of the lifecycle. During this phase, the expression merely accesses the value of name from the customer bean, as is done in immediate evaluation.For a postback request, the JavaServer Faces implementation evaluates the expression at different phases of the lifecycle, during which the value is retrieved from the request, validated, and propagated to the customer bean.
I am not sure开发者_如何学运维 I understand initial request vs. postback request. Does the client browser make two different request to the webserver?
Initial request passes only Restore View & Render Response phases, while postback request process under all phases (Apply Request Values, Validations Phase, etc).
Initial request is created by clicking a link, pasting an URL in address bar, while a postback request is create by posting a form by clicking a submit button or any post request.
Initial request is the request that the browser does in order to display the page with the ${customer.name}
tag. Postback happens when the browser posts some or all page values and then the same page that was posted in the first place is returned to the client. This might happen for example as a result of a validation error.
Knowing if the current view being rendered is a result of a postback is useful. For example you might want to display a message as a result of a postback, but not every time the page is refreshed.
Normally you would have only one initial request, when you go to the browser and write in the URL to your app. This make an HTTP GET request to the server with your cookies e.g. JSESSIONID, but not with a javax.faces.viewid to be restored.
When you have an open page and you do hacky stuff lick: window.location = newUrl -> you will also make an initial request.
When instead you do something like jQuery("#somoeSubmitButton").click(), you will POST to the server and your old view will be restored - and if you ask faces context.isPostback() ? you will get true.
精彩评论