Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 419
Thang Pham Avatar asked May 12 '10 21:05

Thang Pham


People also ask

What is postback request in JSF?

Postback request happens when we click on a button/link for submitting a form. Unlike the initial request, the postback request passes through all the phases. JSF provides a method named isPostback that returns a Boolean value: it returns true for postback request... Unlock full access.

What is the life cycle of JSF JavaServer Faces)?

The lifecycle of a JavaServer Faces application begins when the client makes an HTTP request for a page and ends when the server responds with the page. The JSF lifecycle is divided into two main phases: Execute Phase. Render Phase.

Which FacesContext method skips the render Response Phase in JSF?

If any decode methods or event listeners have called the renderResponse method on the current FacesContext instance, the JavaServer Faces implementation skips to the Render Response phase.

How does execution phase work in JSF JavaServer faces lifecycle?

During this phase, JSF asks container/application server to render the page if the application is using JSP pages. For initial request, the components represented on the page will be added to the component tree as JSP container executes the page.


2 Answers

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.

like image 135
shwetank sharma Avatar answered Oct 12 '22 23:10

shwetank sharma


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.

like image 23
Cesar Avatar answered Oct 12 '22 21:10

Cesar