Receiving an Ajax Response
After the application sends an Ajax request, it is processed on the server side, and a response is sent back to the client. As described earlier, Ajax allows for partial updating of web pages. To enable such partial updating, JavaServer Faces technology allows for partial processing of the view. The handling of the response is defined by the render attribute of the f:ajax tag.
Similar to the execute attribute, the render attribute defines which sections of the page will be updated. The value of a render attribute can be one or more component id values, one of the keywords @this, @all, @none, and @form, or an EL expression. In the following example, the render attribute simply identifies an output component to be displayed when the Ajax action has successfully completed.
<h:commandButton id="submit" value="Submit"> <f:ajax execute="userNo" render="result" /> </h:commandButton> <h:outputText id="result" value="#{userNumberBean.response}" />
However, more often than not, the render attribute is likely to be associated with an event attribute. In the following example, an output component is displayed when the button component is clicked.
<h:commandButton id="submit" value="Submit"> <f:ajax event="click" execute="userNo" render="result"/> </h:commandButton> <h:outputText id="result" value="#{userNumberBean.response}"/>
Note - Behind the scenes, once again the jsf.ajax.request() method handles the response. It registers a response-handling callback when the original request is created. When the response is sent back to the client, the callback is invoked. This callback automatically updates the client-side DOM to reflect the rendered response.