title: How to send ajax callback param with Primefaces?
body: <p>I'm trying to send an Ajax callback with RequestContext but I can't get it work.</p>
  
  <p>I tried the <a href="http://www.primefaces.org/showcase/ui/dialogLogin.jsf" rel="nofollow">Primefaces login demo</a>, but  "args.loggedIn" in the javascript function is always undefined, whereas "args" is an Object. </p>
  
  <p>Here is my code:</p>
  
  <p>dialogLogin.xhtml:</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;h:body&gt;
  &lt;h:outputLink
          id="loginLink" 
          value="javascript:void(0)" 
          onclick="dlg.show()"
          title="login"&gt;
          Click
  &lt;/h:outputLink&gt;
  
  &lt;p:dialog id="dialog" header="Login" widgetVar="dlg"&gt;  
      &lt;h:form&gt;  
  
          &lt;h:panelGrid columns="2" cellpadding="5"&gt;  
              &lt;h:outputLabel for="username" value="Username:" /&gt;  
              &lt;p:inputText value="#{logBean.username}"   
                      id="username" required="true" label="username" /&gt;  
  
              &lt;h:outputLabel for="password" value="Password:" /&gt;  
              &lt;h:inputSecret value="#{logBean.password}"   
                      id="password" required="true" label="password" /&gt;  
  
              &lt;f:facet name="footer"&gt;  
                  &lt;p:commandButton id="loginButton" value="Login" update=""   
                      actionListener="#{logBean.login}"   
                      oncomplete="handleLoginRequest(xhr, status, args)"/&gt;  
              &lt;/f:facet&gt;  
          &lt;/h:panelGrid&gt;  
  
      &lt;/h:form&gt;  
  &lt;/p:dialog&gt;  
  
  &lt;script type="text/javascript"&gt;  
      function handleLoginRequest(xhr, status, args) {  
          if(args.validationFailed || !args.loggedIn) {  
              jQuery('#dialog').effect("shake", { times:3 }, 100);  
          } else {  
              dlg.hide();  
              jQuery('#loginLink').fadeOut();  
          }  
      }  
  &lt;/script&gt;
  &lt;/h:body&gt;
  </code></pre>
  
  <p>LogBean.java:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>@ManagedBean
  public class LogBean {  
  
      private String username;      
      private String password;  
  
      // getters &amp; setters
  
      public void login(ActionEvent actionEvent) {  
          RequestContext context = RequestContext.getCurrentInstance();  
          boolean loggedIn = false;  
  
          if(username != null  &amp;&amp; username.equals("admin") &amp;&amp; password != null  &amp;&amp; password.equals("admin")) {  
              loggedIn = true;  
          } else {  
              loggedIn = false;  
          }  
          System.out.println("loggedIn : " + loggedIn);
          context.addCallbackParam("loggedIn", loggedIn);  
      }
  }  
  </code></pre>
  
  <p>The javascript function "handleLoginRequest" is called, but "args.loggedIn" is always undefined. I can't understand why... </p>
  
  <p>Response sent (I get it from Firebug) is:</p>
  
  <pre class="lang-java prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;partial-response&gt;
      &lt;changes&gt;
          &lt;update id="javax.faces.ViewState"&gt;
              &lt;![CDATA[3585116548358262356:-8608378680794066522]]&gt;
          &lt;/update&gt;
      &lt;/changes&gt;
  &lt;/partial-response&gt;
  </code></pre>
  
  <p>Any help is greatly appreciated!</p>