Results 1 to 2 of 2
  1. #1
    burferd is offline Member
    Join Date
    Jun 2011
    Rep Power

    Default How to add ajax behavior to dynamically created component?

    Using JSF 2.0.

    I have a need to generate components in my backing beans and have them displayed on the page when rendered.
    Creating the component is not an issue, I can do that with the code listed below.
    However I want to add ajax functionality and I do not know how to do that in the backing bean.

    A simple example of an ajax enabled component on an xhtml page would be something like:

    <h:commandButton id="buttonId" action="#{backingBean.buttonAction}" value="Push Me" >
    <f:ajax render="componentName" />

    To create something similar in a backing bean I use the following code in my backing bean:

    button = new HtmlCommandButton();
    button.setId( "buttonId" );
    button.setType( "submit" );
    button.setTitle( "Push this button to....");
    button.setValue( "Push Me" );

    I then add this as a child of a component on the page.

    What I don't know how do do is add the ajax behavior to this compponent.

    Does anyone know how to do this?


  2. #2
    nicephotog is offline Member
    Join Date
    Mar 2012
    Rep Power

    Default Re: How to add ajax behavior to dynamically created component?

    Your better learning one of the newer JSF or faces or struts frameworks that integrate AJAX, but,
    In the above code you need to assign an id= to your button with the java code the way you did above(there is a method for that in the API).
    Assuming here you know DHTML and DOM level 3 DHTML-javascript, you simply get the id="formname:button1" from your JSF page and perhaps an AJAX framework .js script integrated to the page and assign whatever characteristics required onto the button by its output html id with the appropriate AJAX framework method.

Similar Threads

  1. dynamically populate the city combo box based on the values of state combo +ajax+jsp
    By sandy1000 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-29-2010, 10:00 AM
  2. How to resize the component dynamically??
    By Y. Progammer in forum New To Java
    Replies: 14
    Last Post: 03-17-2010, 05:04 PM
  3. Replies: 1
    Last Post: 11-03-2009, 07:07 AM
  4. Replies: 3
    Last Post: 10-27-2009, 02:19 PM
  5. [SOLVED] Can variable names be dynamically created?
    By CJSLMAN in forum New To Java
    Replies: 4
    Last Post: 01-03-2009, 01:06 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts