title: Sending Ajax Request Using JavaScript to JSF
body: <p>Currently, I am working on a web application that uses draw2d library to draw shapes and charts. On the server side I am using Java(JSF). </p>
  
  <p>I can say that 95% of this application is just pure JavaScript. I like to be able to send Ajax requests from inside my JavaScript with no need of using hidden fields such as <code>&lt;f:inputText&gt;</code> (perhaps using jQuery Ajax components?). </p>
  
  <p>I tried to hack around this by adding different hidden JFS component and <code>jsf.ajax.request</code>, but for whatever reason they are not very reliable and sometimes they don't send the ajax request. </p>
  
  <p>Any suggestion? Also, about jQuery, I am not sure how to process the request on the server side.</p>
  
  <p><strong>Answer:</strong> I ended up using what Dave suggested. I previously tried to use jsFunction from this <a href="http://livedemo.exadel.com/richfaces-demo/richfaces/jsFunction.jsf?c=jsFunction" rel="nofollow">link</a>, but I got error. Apparently, the problem is , which is not yet implemented in Richfaces 4. However, if you use , as dave mentioned it works perfectly.</p>
  
  <p>One more point, the beans didn't work for me as Dave potsed. I had to change it as follows:
      @ManagedBean(name = "jsFunctionBean")
  @SessionScoped
  public class JsFunctionBean {</p>
  
  <pre><code>/**
   * Test String name
   */
  private String name;
  
  public String getName() { return this.name; }
  public void setName(String name) { this.name = name; }
  
  /**
   * Test boolean
   */
  private boolean test;
  public boolean getTest() { return this.test; }
  public void setTest(boolean test) { this.test = test; }    
  
  /**
   * Action Method 
   * 
   * @return
   */
  public String getActionMethod() {
      return null;
  }
  
  public String actionMethod(){
      this.test = true;
      this.name = "Dave";
      return null;
  }
  }
  </code></pre>
  
  <p>I am not sure why this is the case, but if I remove getActionMethod or actionMenthod I would get error!</p>