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!!

13 comments:

  1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
    Cyber Security Projects for Final Year

    JavaScript Training in Chennai

    Project Centers in Chennai

    JavaScript Training in Chennai

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

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

    ReplyDelete
  4. 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
  5. This comment has been removed by the author.

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

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

    ReplyDelete
  8. IEEE Cloud computing DOamin is a general term for anything that involves delivering hosted services over the Internet. cloud computing projects The cloud projects for cse is a metaphor for a global network of remote servers which operates as a single ecosystem, commonly associated with the Internet. IEEE FInal Year Networking Projects for CSE Domains Networking Projects cloud computing is the delivery of computing projects services—including servers, storage, databases, networking projects, software, analytics, and intelligence


    JavaScript Training in Chennai


    JavaScript Training in Chennai

    ReplyDelete
  9. 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
  10. every sales manager and store owner should have a training in sales management* la web design

    ReplyDelete
  11. 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
  12. Very informative post. Your current Website style is awesome as well! website design agency

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...