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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:30:11+00:00 2026-05-26T18:30:11+00:00

In my code, I have the following objects to implement a shopping cart: public

  • 0

In my code, I have the following objects to implement a shopping cart:

public class CartItem {
    ...
    public int id;
    public int quantity;
    ...
}

public class Partner {
    ...
    public List<CartItem> listOfItems;
    ...
}

public class Cart implements Serializable {
    ...
    private List<Partner> listOfPartners;
    ...
}

In the ViewCart.xhtml page, I list the items as following:

...
<ui:repeat value="#{cartManagedBean.cart.listOfPartners}" var="p">
    <ui:repeat value="#{p.listOfItems}" var="i">
        <h:form>
            ...
            <h:inputText size="3" value="#{i.quantity}" />

            <h:commandButton value="Update" />
            ...
        </h:form>
    </ui:repeat>
</ui:repeat>
...

And this is my ManagedBean:

@ManagedBean
@SessionScoped
public class CartManagedBean {
    ...
    private Cart cart;
    ...
}

All the getters and setters methods are properly done. Hence, I expected that when I click the update button, the quantity of the corresponding Item would be updated. However, when I test the function, only the last item in the list can be updated.

I’d be very grateful if someone could give me an advice on how I should tackle this problem.

UPDATE: I managed to make it work by replacing ui:repeat with h:dataTable. I think my knowledge of ui:repeat should be wrong somewhere. When I was using ui:repeat, I saw that the HTML generated was something like:

<form>
    ...
    <input type="submit" id="jdt:51;jdt52" />
    ...
</form>
<form>
    ...
    <input type="submit" id="jdt:51;jdt52" />
    ...
</form>

In other words, all the Items were generated with the same ID. I even tried to make the ID of the input for quantity unique by appending the unique ID of each item to the ID of the input as following:

<h:inputText id="quantity#{i.id}" size="3" value="#{i.quantity}" />

However, in the HTML result, I saw that the ID was something like:

<form>
    ...
    <input type="submit" id="jdt:51;jdt52;quantity203" />
    ...
</form>
<form>
    ...
    <input type="submit" id="jdt:51;jdt52;quantity203" />
    ...
</form>

In other words, the ID of the 1st Item was repeated for all subsequent items. Even though I haven’t fully understood how variables are updated with new values, I think this is the reason why only the last item can be updated.

I’d be very grateful if someone could explain this further for me so that I won’t make the same mistake again =).

  • 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-26T18:30:11+00:00Added an answer on May 26, 2026 at 6:30 pm

    You seem to be using Mojarra. The <ui:repeat> is totally broken in Mojarra. I can reproduce your problem even on the latest Mojarra 2.1.4. It however works 100% when using MyFaces 2.1.3. I’ve reported it to the Mojarra guys as issue 2243.

    You have 3 options:

    • Replace Mojarra by MyFaces.
    • Use <c:forEach> instead of <ui:repeat>. This only works if the <c:forEach> is not by itself inside some UIData component.
    • Use an UIData component instead of <ui:repeat>.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code (changed object names, so syntax/spelling errors ignore). public class
Say you have the following class public class AccessStatistics { private final int noPages,
I have the following code that creates two objects (ProfileManager and EmployerManager) where the
I have the following code in my index view. latest_entry_list = Entry.objects.filter(is_published=True).order_by('-date_published')[:10] for entry
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I have the following code that creates a serverside object of the xmlhttp class.
I have the following code: public void BeginConvert(object data) { ConverterData cObject = (ConverterData)data;
I have the following example code: class A(object): def __init__(self, id): self.myid = id
Consider the following example code: class Foo { }; class Bar : public Foo
I have the following class class CItem { public: CItem(CRegistry &Registry) _Registry(Registry) {Registry.Register();} ~CItem()

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.