Request Context

RequestContext is a feature with various handy utilities.

  • Update component(s) programmatically.
  • Execute javascript from beans.
  • Add ajax callback parameters.
  • ScrollTo a specific component after ajax update.
New User

    Source

    <h:form>
    	<p:panel id="panel" header="New User">
    		<p:messages />
    		<h:panelGrid columns="2">
    			<h:outputLabel for="firstname" value="Firstname: *" />
    			<p:inputText id="firstname" value="#{userController.user.firstname}" required="true"/>
    			
    			<h:outputLabel for="surname" value="Lastname: *"  />
    			<p:inputText id="surname" value="#{userController.user.lastname}" required="true"/>
    		</h:panelGrid>
    	</p:panel>
    
    	<p:commandButton value="Save" actionListener="#{userController.saveUser}" oncomplete="handleComplete(xhr, status, args)" />
    
        <p:log />
    </h:form>
                        
    <script type="text/javascript">
    function handleComplete(xhr, status, args) {
    	if(args.validationFailed) {
    		PrimeFaces.debug("Validation Failed");
    	} 
        else {
    		PrimeFaces.debug("Save:" + args.saved);
    		PrimeFaces.debug("FirstName: " + args.user.firstname + ", Lastname: " + args.user.lastname); 
    	}
    }
    </script>