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

  • Home
  • SEARCH
  • 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 988429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:38:09+00:00 2026-05-16T05:38:09+00:00

I am having some problems updating to the right value. On the page which

  • 0

I am having some problems updating to the right value. On the page which you can see part of down under, there is a parameter ‘change’. I think that this parameter is causing jsf to update the backing bean with the old value and thus do nothing.

<h:panelGroup id="panel0">
            <h:form id="changeForm">
                <h:messages/>
                <!--This retains the parameter "change"-->
                <input type="hidden" name="change" value="#{param.change}"/>
                <!--CHANGE NAME-->
                <h:panelGrid id="panel1" rendered="#{param.change == 'name'}" columns="2">
                    First Name:
                    <h:inputText id="firstName" value="#{changeInfoBean.firstName}"/>
                    Last Name:
                    <h:inputText id="lastName" value="#{changeInfoBean.lastName}"/>
                     <f:facet name="footer">
                        <h:panelGroup style="display:block; text-align:center">
                            <h:commandButton value="Submit Name" action="#{changeInfoBean.changeName}"/>
                        </h:panelGroup>
                    </f:facet>
                </h:panelGrid>
          </h:form>
    </h:panelGroup>

I have also tried having the two inputText fields set to immediate=”true” but this will not work either.

My backing bean:

@Named(value="changeInfoBean")
@SessionScoped
public class ChangeInfoBean {

    private String email;
    private String firstName;
    private String lastName;

    /** Creates a new instance of ChangeInfoBean */
    public ChangeInfoBean() {
            FacesContext context = FacesContext.getCurrentInstance();
            // Gets the user which is currently logged in
            LoginBean bean = (LoginBean) context.getExternalContext().getSessionMap().get("loginBean");
            BasicUser user = bean.getUser();
            this.email = user.getEmail();
            this.firstName = user.getFirstName();
            this.lastName = user.getLastName();

    }

    public void changeName() {
        Session session = null;
        try {
            session = HibernateUtil.getSessionFactory().openSession();
            Transaction tx = session.beginTransaction();
            String hql = "update BasicUser set firstName = :newFirstName, lastName = :newLastName "
                    + "where email = :email";
            Query query = session.createQuery(hql);
            query.setString("newFirstName", this.firstName);
            query.setString("newLastName", this.lastName);
            query.setString("email", this.email);
            int rowCount = query.executeUpdate();
            tx.commit();
            System.out.println("Rows affected: " + rowCount);
            }
            catch(Exception e) {
                e.printStackTrace();
            }
            finally {
                session.close();
            }
    }
    public String getLastName() {
        System.out.print("I am getting my lastName: " + this.lastName);
        return lastName;
    }

    public void setLastName(String lastName) {
        System.out.print("I am updating my lastName to: " + this.lastName);
        this.lastName = lastName;
    }
}

When I try to change my lastName from Lindhardt to something new I get this

INFO: START PHASE RESTORE_VIEW 1
INFO: END PHASE RESTORE_VIEW 1
INFO: START PHASE APPLY_REQUEST_VALUES 2
INFO: END PHASE APPLY_REQUEST_VALUES 2
INFO: START PHASE PROCESS_VALIDATIONS 3
INFO: I am getting my lastName: Lindhardt
INFO: END PHASE PROCESS_VALIDATIONS 3
INFO: START PHASE UPDATE_MODEL_VALUES 4
INFO: I am updating my lastName to: Lindhardt
INFO: END PHASE UPDATE_MODEL_VALUES 4
INFO: START PHASE INVOKE_APPLICATION 5
INFO: Hibernate: update coffeedrinkers.basic_user set First_Name=?, Last_Name=? where Email=?
INFO: Rows affected: 1
INFO: END PHASE INVOKE_APPLICATION 5
INFO: START PHASE RENDER_RESPONSE 6
INFO: I am getting my lastName: Lindhardt
INFO: END PHASE RENDER_RESPONSE 6

So the backing bean never recieves the new lastName but just updates the model with the old lastName. Isn’t that weird:)

  • 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-16T05:38:10+00:00Added an answer on May 16, 2026 at 5:38 am

    With this you’re referencing the current instance’s variable, not the local (passed-in) variable. You’re printing the current instance’s variable before it has been set with the passed-in variable, while your interest is rather the passed-in one.

    public void setLastName(String lastName) {
        System.out.print("I am updating my lastName to: " + this.lastName);
        this.lastName = lastName;
    }
    

    Change it to

    public void setLastName(String lastName) {
        System.out.print("I am updating my lastName to: " + lastName);
        this.lastName = lastName;
    }
    

    or

    public void setLastName(String lastName) {
        this.lastName = lastName;
        System.out.print("I am updating my lastName to: " + this.lastName);
    }
    

    and it’ll print the right one.


    Update: as per the comments, the above only fixes the problem partly. After all, still the wrong value is been persisted/redisplayed. This seems to be related to the CDI’s @Named annotation. It caused the bean to be seemingly resonctructed on every phase of the JSF lifecycle. Replacing it by JSF standard @ManagedBean annotation did fix the issue.

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

Sidebar

Related Questions

I'm having some problems integrating MS MapPoint 2009 into my WinForms .Net 2.0 application
I have been having some problems trying to get my PHP running. When I
I'm having some problems with the ranking used by fulltext search in SQL Server.
I'm having some problems with a datagridview element I'm using in VS2008. This DataGridView
I'm having some problems getting my object to gracefully fail out if an invalid
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I'm having some problems with my WCF server and client connections. If I use
I'm having some problems displaying the contents of one NSArrayController in two windows defined
I am currently having some problems with <li> in IE6 essentially my code looks
I'm having some minor problems with some animations I'm trying to set up. I

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.