Time for action – updating UI components using RequestContext.update()
In this section, we will demonstrate how to update client-side view components from the server side using the following steps:
Create a form with an input field and a submit button as follows:
<h:form id="form1"> <h:panelGrid columns="2"> <h:outputLabel value="EmailId" /> <p:inputText id="emailId" value="#{requestContextController.emailId}"/> <p:commandButton id="submitBtn" value="Submit" actionListener="#{requestContextController.handleSubmit}" /> </h:panelGrid> <h:outputText value="You have Entered : #{requestContextController.emailId}" /> </h:form>
In the action handler method, update the form component using the
RequestContext.update()
method as follows:public void handleSubmit(ActionEvent ae) { RequestContext.getCurrentInstance().update("form1"); }
What just happened?
We got a RequestContext
instance using RequestContext.getCurrentInstance()
and...