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 8927473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:13:38+00:00 2026-06-15T08:13:38+00:00

I am iterating over a List of Items with <ui:repeat> . Inside I use

  • 0

I am iterating over a List of Items with <ui:repeat>. Inside I use javascript to process some data for each iteration and want to output it in a div that is created for every iteration.
The following code will of course output the data only for the last iteration (the ones before are overwritten). I can’t think of an approach how to do it.

this is the jsf code:

<ui:repeat var="item" value="#{someBean.items}">
    <script type="text/javascript">
        var item = "#{item.id}";
        showItem();
    </script>
    <div id="#{item.id}"></div>
</ui:repeat>

this is the function:

function showItem(){
    document.getElementById(item).innerHTML = 'this is an item';
}
  • 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-06-15T08:13:39+00:00Added an answer on June 15, 2026 at 8:13 am

    Try doing this:

    <ui:repeat var="item" value="#{someBean.items}">
        <div id="#{item.id}"></div>
        <script type="text/javascript">
            showItem("#{item.id}");
        </script>
    </ui:repeat>
    

    –

    function showItem(item){
        document.getElementById(item).innerHTML = 'this is an item';
    }
    

    The reason being is that even though you have each var wrapped in a script tag they’re all on the global scope, hence over writing each other on each iteration of the loop.

    To give each script block it’s own scope you could wrap the vars in a self executing function like this, but with your current logic it seems like it’d be a bit of an overkill:

    <ui:repeat var="item" value="#{someBean.items}">
        <div id="#{item.id}"></div>
        <script type="text/javascript">
        (function(){
            var item = "#{item.id}";
            showItem(item);
        })();
        </script>
    </ui:repeat>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want avoid iterating over a nil array. My bad solution: if nil!=myArr myArr.each
Is iterating over some_dict.items() as efficient as iterating over a list of the same
So I'm iterating over items in a list in this way: for virus in
Consider the following list: items = ['about-conference','conf'] Iterating over the list using the following
I'm already iterating over several hashmaps each of sizes 20-40 items so would it
I am iterating over a list and I want to print out the index
I have a select list with multiple items which I want to be able
I'm looking for a pythonic way of iterating over first n items of an
Im iterating over a list to create fieldsets on the page. the last fieldset
In MVC, I constructed a table in a view, by iterating over a 'List'

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.