Results 1 to 11 of 11
  1. #1
    Kanna is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default Dynamic check box creation + Ajax

    I have to create multiple check boxces dynamically depends on the selection of the drop down box. We are developing Struts application and wanted to implement Ajax to dynamically load the page with check boxces (html:multibox). I am looking for the help how to handle this situation?

    Idon't have the code to post it here.
    It would be appreciate if any one can help me on this.

    Thanks in advance,
    Rama.

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    What exactlly is you don't know about this? Is it a ajax function, or you know ajax and you just need to place a right call to struts so confuses you how? Are you gonna put this on some JSP that is 'view' or you need it on 'form'?

  3. #3
    Kanna is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Thanks for the quick response.

    I know Ajax and wanted to write an Ajax statement in the JSP to set the String[] (which consistes of array of String values for the check boxces)coming from the Struts Action to the ID/Name of the <html:multibox> tag defined in the same JSP.

    I hope I didn't confuse you.

    Thanks,
    Rama

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    The struts code (and tags) is executed on the server.
    Your Ajax calls are made on the client.

    Your Ajax call needs to use Javascript to create checkboxes...it can't use Struts tags to do that.

  5. #5
    Kanna is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    ok..understand..

    can I get sample code to create the check boxces dynamically with Javascript and the scriplet of the JSP code to define/declare the html checkbox/multibox ?

    Thanks,
    Rama

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    Actually, rereading this, I'm not sure what it is (functionally) you want. What is the user going to see when the page loads up? When is this Ajax call being made, and what then happens to the clients window?

  7. #7
    Kanna is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    ok..let me explain in detail.

    In the JSP,when the page load,it will show only a drop down box.If select a value from the drop down,I wanted to make Ajax call to Struts Action to get the String[] (ex: Onion,Tomato,Cheese for selectedPizza from the drop down)and dynamically create the checkboxces in the JSP.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    Ah...this is the thread I'm mixing up with the shuttle thing, for some unkown reason!

    OK, so user selects someting in drop down.
    That something is associated with a certain collection of checkboxes (ie options).

    I'm not sure how multibox works, but would you plan on having one multibox collection per drop down selection? Or indeed, can you?

    That would give you your Struts mapping between fields. Have all of those on the page, in named <div>s. Hide all the divs. On select, show the relevant div.

    This is off the top of my head at the end of a long day, so take it with a pinch of salt.

  9. #9
    Kanna is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default

    Yes Tolls ..your understanding is right.

    I implemented show/hide logic to display/not diaply content in the JSP when onload the page.Now I need to have a piece of Javascript which will generate the check boxces(may not be a Struts <html:multibox>) and Java scriplet to define the <div id= " "> tag in the JSP depends on the selectedItem from the drop down.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    You don't need to define the checkboxes.
    You should have something like (syntax may be a bit out, as I don't know the syntax for multibox):
    Java Code:
    for each thing in the drop down
        <div id="some reference to the drop down value">
            <html:multibox (same reference here?)/>
        </div>
    So that gives you a unique multibox for each opf the drop down entries. All your code then has to do is show/hide onChange() of the drop down. And that bit you'll have to do since that's Javascript.

  11. #11
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default

    You have dropdown list of Pizzas.
    When you select one Pizza, you want ingredients for that Pizza to show up.
    Each ingredient is checkbox so you can choose to put it or not on your pizza.

    Is this valid description of what you are doing?

    First, in you have your pizza/ingredient static catalog, why simply not load it all on client, and let JS solve dependencies and show proper ingredient for pizza you choose, all on one page without reload or ajax calls?

    If you think it is too much data to load, or you are simply Ajax fan, do it your way. Here is a link to clear things up about multibox in Struts:

    http://www.laliluna.de/download/stru...ultibox-en.pdf

    Tolls is right - no checkbox creation in JS - you do that in
    multibox and you will find in previous link iteration example, all you have to do it create reference between pizza and its ingredients.

Similar Threads

  1. JVM creation failed
    By RogerP in forum NetBeans
    Replies: 12
    Last Post: 10-08-2011, 09:33 PM
  2. Replies: 5
    Last Post: 07-09-2010, 06:14 AM
  3. dynamic tree creation in jsp
    By rummy in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 01-11-2010, 12:25 PM
  4. dynamic creation of jpanel
    By masa in forum AWT / Swing
    Replies: 1
    Last Post: 12-18-2008, 11:36 AM
  5. bmp creation
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 12-17-2008, 05:33 PM

Posting Permissions

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