PrimeFaces Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Introducing the RequestContext utility

RequestContext is a utility class provided by PrimeFaces with the following features, which come in handy at times:

  • Update UI components from Managed Bean methods programmatically
  • Execute JavaScript from Managed Bean methods
  • Add AJAX callback parameters
  • ScrollTo a specific component after the AJAX update

The RequestContext utility class can be used with both AJAX and Non-AJAX requests. We can also use the requestContext.isAjaxRequest() method to determine whether the current request is an AJAX or Non-AJAX request.

Updating UI components

Normally we use the update attribute to specify the component ID(s) that needs to be updated after an AJAX request is completed.

We can also update the components using the org.primefaces.context.RequestContext utility function.