Wednesday, March 13, 2013

Easy way to add AJAX action to HTML element with Richfaces and Primefaces

In some cases, HTML elements still need to be used in JSF due to certain limitations.
But HTML component is lack of AJAX support.
Thus, the objective of this post is to show how to add AJAX event to a HTML element without writing any javascript.

this can be achieved with <a4j:jsFunction /> in Richfaces and <p:remoteCommand /> in Primefaces.

Steps:
1. Define the AJAX action to be invoked in xhtml.
(a) Richfaces
    <a4j:jsFunction
        name="updateIndexWhenOnclick"
        action="#{testBean.updateIndex}"
        render="[component id to render]">
    </a4j:jsFunction>

(b) Primefaces
    <p:remoteCommand 
        name="updateIndexWhenOnclick" 
        action="#{testBean.updateIndex}" 
        update="[component id to update]">
    </p:remoteCommand>

2. invoke the AJAX action in HTML element.
<input type="checkbox" onclick="updateIndexWhenOnclick();" />

Done!!

11 comments:

  1. Thank you very much for this useful article. I like it. write essays for money

    ReplyDelete
  2. I enjoy your writing style really enjoying this web site . website design company nyc

    ReplyDelete
  3. Wow really glad i came across your internet site, i??ll be sure to visit back now i??ve bookmarked it??. web design new york

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Usually I don’t read this kind of stuff, but this was really interesting! branding agency sf

    ReplyDelete
  6. You got a very fantastic website, Glad I observed it through yahoo. design agency san francisco

    ReplyDelete
  7. site promotion will always be a tedious job but you can outsource site promotion on some indian or pakistani guy- los angeles web agency

    ReplyDelete
  8. every sales manager and store owner should have a training in sales management* la web design

    ReplyDelete
  9. the travel packages that i have seen on the internet are sometimes oversold, they are cheap yet the inclusions sucks` web design agency los angeles

    ReplyDelete
  10. Very informative post. Your current Website style is awesome as well! website design agency

    ReplyDelete
  11. Adding AJAX to web pages has never been easier for us than it is now. And I give you credit for making it easy. You are absolutely wise man. Dissertation Writing Service

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...