File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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: 3135

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).

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
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: 17423

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.

An IDE is no substitute for an Intelligent Developer.
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.
I agree. Here's the link:
subject: JSF problem with form (update user)
jQuery in Action, 3rd edition