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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:32:03+00:00 2026-05-30T01:32:03+00:00

I have an application that stores users in a database. I want that administrators

  • 0

I have an application that stores users in a database. I want that administrators can upate the data of those users and tried to create a dataTable that calls a bean to get a list of users and iterates over the users to output their data. I output the data in inputText fields so that the administrator is able to edit their data. Next to the inputText fields is a commandLink to save the changes, which should call a bean-method (sessionScoped) to merge changes into the database.

I tried to do this with a dataTable and also manually with a foreach. Neither of them worked.

The problem is that in the bean-method that is called when the link is clicked, the values are still the old ones and not the edited ones (I want it to be the new values from the inputText fields). I did some research an read about the actionListener. So I added an actionListener to the commandLink that is supposed to copy the new values of the inputText fields to a bean-attribute, but it didn’t work either.

This is the code of my jsf-page:

<c:forEach items="#{UserBean.getUserList()}" var="customer">
      <tr>
          <h:form>
              <td>
                  <h:inputText disabled="true" value="#{customer.username}"/>
              </td>
              <td>
                  <h:inputText value="#{customer.firstname}"/>
              </td>
              <td>
                  <h:inputText value="#{customer.lastname}"/>
              </td>
              <td>
                  <h:inputText value="#{customer.email}"/>
              </td>
              <td>
                  <h:commandLink action="#{UserBean.update()}" value="Save changes">
                      <f:setPropertyActionListener target="#{UserBean.user}" value="#{customer}" />
                  </h:commandLink>
              </td>
          </h:form>
      </tr>
 </c:forEach>

This is my bean:

@ManagedBean(name="UserBean")
@SessionScoped
public class UserBean implements Serializable{

    private Users user;

    private List<Users> userList;


    public UserBean() {
        user = new Users();
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public String update(){
        System.out.println(user.getFirstname());

        return null;
    }

    public List<Users> getUserList(){
        userList = findAll();
        return userList;
    }

    public void setUserList(List<Users> userList){
        this.userList = userList;
    }

    public List<Users> findAll(){
        if(userSessionBean.getSessionUser().getUgroup() > 1){
            userList = em.createNamedQuery("Users.findAll")
                    .getResultList();
            return userList;
        }
        else{
            userList = em.createNamedQuery("Users.findById")
                    .setParameter("id", userSessionBean.getSessionUser())
                    .setMaxResults(1)
                    .getResultList();
            return userList;
        }
    }
}

Does anyone know what I do wrong or what the problem could be?

  • 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-30T01:32:05+00:00Added an answer on May 30, 2026 at 1:32 am

    You’re loading the model in the getter method.

    public List<Users> getUserList(){
        userList = findAll();
        return userList;
    }
    

    So everytime when the getter is called, it will return a fresh new model and override any changes previously done on the model.

    Move that line to the bean’s (post)constructor method.

    @PostConstruct
    public void init() {
        userList = findAll();
    }
    
    public List<Users> getUserList(){
        return userList;
    }
    

    Once you’ve fixed it, just use a <h:dataTable>. This results in less boilerplate code.

    See also

    • Why JSF calls getters multiple times
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that stores data in an Oracle database. I want to
I have to create a user in a third party application that stores its
I have an application that stores images in a database. Now I have learned
Assume I have a application that stores data,gets data and processes data and stores
I have made a java application that stores data from a .csv file to
We have an application that stores its database files in a subfolder of the
I have a swing Java application that preserves a lot of data (you can
I have an application that lets users build things in JS. I want the
We have an application that uses Windows authentication to authenticate users with the database,
I have developed a web application driven by a mysql database that stores information

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.