Time for action – adding callback parameters using RequestContext.addCallbackParam()
In this section, we will see how to add callback parameters to an AJAX response payload by performing the following steps:
Create a form with an input field and submit button using the following code:
<h:form id="form1"> <h:panelGrid columns="2"> <h:outputLabel value="EmailId" /> <p:inputText id="emailId" value="#{requestContextController.emailId}" required="true"/> <p:commandButton id="submitBtn" value="Submit" actionListener="#{requestContextController.handleSubmit}" oncomplete="handleComplete(xhr, status, args)"/> </h:panelGrid> <h:outputText value="You have Entered : #{requestContextController.emailId}" /> </h:form>
Implement the
oncomplete
callback JavaScript functionhandleComplete()
as follows:<script type="text/javascript"> function handleComplete(xhr, status, args) { if(args.validationFailed) { alert...