Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4258564
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:39:59+00:00 2026-05-21T05:39:59+00:00

I am trying to generate div tags dynamically depending on the number of items,

  • 0

I am trying to generate div tags dynamically depending on the number of items, contained in the ‘deviceSel’ from the backing beans. For each of the div tag, I am populating it by calling the ‘generateSparkLine’ function that is present in a JS file – ‘Reports_Cap’. I need to pass the id of the iv tag for the function to populate the data in the corresponding ‘div’ tag.

In my current code, the divs get created with the same id and hence, the same portion gets populated onclick. Could someone help me with a way to dynamically assign ids to the div tags from the JSF file? Also, div tag is not letting me use the “onload” event and that is the reason I am using the “onclick”. How could I go about modifying it so that I could get the div tags populated when the page opens up?

<div>
    <ui:repeat var="deviceSel" value="#{reportViewproto.selectedDevices}">
        <h:outputText value="#{deviceSel}" />
        <div id="chartDiv" style="width:600px; height:400px;" onclick="Reports_Cap.generateSparkLine('chartDiv', 'generateSparkLine')"></div>
        <br />
   </ui:repeat>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:40:00+00:00Added an answer on May 21, 2026 at 5:40 am

    Several ways.

    If the JS generateSparkLine() function is under your control and you’re actually using the id to get the element from the document by ID, then just get rid of id attribute and replace the onclick by

    onclick="Reports_Cap.generateSparkLine(this, 'generateSparkLine')"
    

    This way you don’t need the ID. You already have the element as 1st argument in the function.


    Or if it is not under your control and/or you don’t use it to obtain the element by ID and you’re using Facelets 2.x, then introduce a loop counter by varStatus attribute of <ui:repeat> and suffix the ID values with it.

    <div>
        <ui:repeat var="deviceSel" value="#{reportViewproto.selectedDevices}" varStatus="loop">
            <h:outputText value="#{deviceSel}" />
            <div id="chartDiv_#{loop.index}" style="width:600px; height:400px;" onclick="Reports_Cap.generateSparkLine('chartDiv_#{loop.index}', 'generateSparkLine')"></div>
            <br />
       </ui:repeat>
    </div>
    

    If you are still on Facelets 1.x, your best bet is JSTL <c:forEach> which also supports a varStatus attribute the same way, with the only difference that it runs during view build time, not during view render time and thus you won’t be able to use it in another UIData component.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to dynamically segment each generated-label and hardcoded input pair with div tag's.
i am trying to generate the following list in asp.net? <div class=items> <!-- 1-5
I am trying to generate an html div in asp.net. Since a div is
I'm trying to generate the following html code using cl-who: <html> <body> <div id=cnt_1></div>
I'm trying to generate a dynamic table using CSS: <html> <head> <style> div.el1, div.el2
I'm trying to dynamically create a div to show error messages using jquery. I'm
I'm trying to generate this html hierarchy in my zend_form display group: <div class=settings>
In the JSFiddle, I am trying to generate divs dynamically using javascript. Those divs
Dear experts, I was trying to dynamically generate DOM elements using JS. I read
Hello I'm trying to dynamically generate some inputs for my form, but it's not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.