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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:40:49+00:00 2026-06-09T14:40:49+00:00

I use a arrayList. I want data store in it from Entity class.But it

  • 0

I use a arrayList. I want data store in it from Entity class.But it store current data and previous data remove from it.
My JSF page Code:

  <html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    <h:form>
        <h:outputText value="ID"/><br/>
        <h:inputText value="#{dataTestBeans.data.id}"/><br/>
        <h:outputText value="Name"/><br/>
        <h:inputText value="#{dataTestBeans.data.name}"/><br/>
        <h:outputText value="Address"/><br/>
        <h:inputText value="#{dataTestBeans.data.address}"/><br/>
        <h:outputText value="Birth Day"/><br/>
        <h:inputText value="#{dataTestBeans.data.birthDay}"/><br/>
        <h:commandButton action="#{dataTestBeans.abc}" value="Submit" />
    </h:form>
    <h:form>
        <c:forEach items="#{dataTestBeans.testArray}" var="dataTest">
            <h:outputText value="#{dataTest.id}"/><br/>
            <h:outputText value="#{dataTest.name}"/><br/>
            <h:outputText value="#{dataTest.address}"/><br/>
            <h:outputText value="#{dataTest.birthDay}"/><br/>
        </c:forEach>
    </h:form>
  </h:body>
 </html>

My Entity Class code:

@ManagedBean(name = "person")
@SessionScoped
public class Person{

private String id;
private String name;
private String address;
private String birthDay;

public Person() {
}
    //getter and setter all veriable

}

My controller Beans code:

@ManagedBean(name="dataTestBeans")
@SessionScoped
public class DataTestBeans {

private Person dataArray;
private List<Person> person = new ArrayList<Person>();   

public DataTestBeans() {
 }

public Person getData() {
  if (dataArray == null) {
      dataArray = new Person();
  }
 return dataArray;
 }

public void abc() {
   person.add(dataArray);
 }

public List<Person> getTestArray() {
  return person;
 }

public void setTestArray(List<Person> person) {
    this.person = person;
  }
}

When I run it show the current data

  • 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-09T14:40:50+00:00Added an answer on June 9, 2026 at 2:40 pm

    You’re reusing the same reference for every data entry. Hence you’re basically overwriting it everytime. You should be creating a new one after you’ve added the filled entry in your abc() method.

    Replace the following part in your current code:

    private TestArray dataArray;
    private List<TestArray> testArray = new ArrayList<TestArray>();
    
    public DataTestBeans() {
    }
    
    public TestArray getData() {
        if (dataArray == null) {
            dataArray = new TestArray();
        }
        return dataArray;
     }
    
    public void abc() {
        testArray.add(dataArray);
    }
    

    by

    private TestArray dataArray;
    private List<TestArray> testArray;
    
    public DataTestBeans() {
        dataArray = new TestArray();
        testArray = new ArrayList<TestArray>()
    }
    
    public TestArray getData() {
        return dataArray;
     }
    
    public void abc() {
        testArray.add(dataArray);
        dataArray = new TestArray();
    }
    

    See also:

    • Recommended JSF 2.0 CRUD frameworks (a better CRUD example)

    Unrelated to the concrete problem, your class and variable namings are non-sensible and very confusing and therefore it’s hard for others to quickly interpret the code and spot the problem. Rename TestArray to Person, rename dataArray to person, rename testArray to persons and rename DataTestBeans to PersonManager or something and your code becomes instantly much more self-documenting and easier to interpret.

    private Person person;
    private List<Person> persons;
    
    public PersonManager() {
        person = new Person();
        persons = new ArrayList<Person>()
    }
    
    public Person getPerson() {
        return person;
     }
    
    public void add() {
        persons.add(person);
        person = new Person();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Android Application class (MyApplication.java) for store data in some ArrayList
i want to store some data in my neo4j database. i use spring-data-neo4j for
I want to store a couple of sockets in an ArrayList/NSMutableArray, but the sockets
I want my app to hold data from ArrayList in file in between sessions.
I have an ArrayList that I want to use to hold RaceCar objects that
I try to use the following code: ArrayList<String> Map<String, String> Eclipse complains about both
I am trying to use org.apache.commons.collections.CollectionUtils in android with following code import java.util.ArrayList; import
My requirement is to store the large chunk of data (String value) but i
I hava a method setData(ArrayList<super> list) , so anyone who want set data can
After constructing the bean, I want to retrieve data from the database, using the

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.