O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. 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>
  2. In the action handler method, execute the JavaScript call,

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required