This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes JSF problem with form (update user) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF problem with form (update user)" Watch "JSF problem with form (update user)" New topic

JSF problem with form (update user)

Oleksandr Hubachov

Joined: Jun 16, 2013
Posts: 3
Hi, all. I'm new in JSF and hope on your help. My task is to write simple CRUD application (JSF+Hibernate). I have a problem with Update operation. On page I choose user to update, than click button Update. Opens page with form, where all field filled of user information. Than I change something and click Update. But form become clean and method update() in bean does not calls. When I click to this button second time, this method is called, but i need to write user information manually. Why method does not calls first time? Code:
List of users:

Page of update:

Bean class

Thanks for your answers
K. Tsang

Joined: Sep 13, 2007
Posts: 2379

Why does your update() method call "update(contructUser())"? And in your constructUser() method, you are doing new User()... so when you call update, it will create a new instance of User making the original data lost.

In your JSF page you can call update(user) directly and pass in the user object to your bean. That way you can simply do session.update(user).

Oleksandr Hubachov

Joined: Jun 16, 2013
Posts: 3
It does not matter. Method does not calls at any case.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019

The following constructs are incorrect:

The primary purpose of EL is not to act as a programming language, it is to permit specifying bean property or method references. So, for example, your commandButton should be coded like this:

You did not indicate how (or even if) you associated class UserBean with the EL object named "user". So we need to see the bean annotations or faces-config.xml entry that defines the UserBean as a JSF Managed Bean.

Customer surveys are for companies who didn't pay proper attention to begin with.
Oleksandr Hubachov

Joined: Jun 16, 2013
Posts: 3
Thanks for your answers. I find an error. This method working correctly (even action="#{user.load()}" and action="#{user.load()}"). Problem is in p:calendar and p:selectOneMenu . I need to write right converter, but i don't know how. If i delete from page information about gender, nationality and birthday, all will be ok. I will google and post here a solution.
It is sorta covered in the JavaRanch Style Guide.
subject: JSF problem with form (update user)