Time for action – executing JavaScript using RequestContext.execute()
We will now take a look at how to execute client-side JavaScript code from server-side code by performing the following steps:
Create a form with a Dialog component using the following code:
<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> <p:dialog header="Information" widgetVar="dlg" closeOnEscape="true" modal="true"> You have Entered : #{requestContextController.emailId} </p:dialog> </h:form>
In the action handler method, execute the
JavaScript
call,dlg.show(),
to display a dialog widget using theRequestContext.execute()
method. Use the following code for the same:public void handleSubmit(ActionEvent ae) { RequestContext...