0

I am new to JSF, I was trying to do simple CRUD application, I added the following

  1. DAO to access database
  2. Employee cdi bean with session scope
  3. search, add and edit jsf pages

when I press on edit button to edit employee. everything goes fine, But because it is session scope, when I try to add new employee the text fields get populated automatically with the data from the last edit employee because they are still there in the session.

Well as trivial solution i tried to downgrade the scope of the CDI bean to be request scope but, in this case, it become invisible to my page, it throws exception that this bean does not exist. so what is the solution for this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1512999
  • 237
  • 2
  • 6
  • 19
  • You can try `@ConversationScoped`. – Tom Sep 07 '14 at 05:53
  • After editing as well as after adding set the values to defaults. For examle `String username;` as `username = "";` or try setting `username = null;`. see what happens – Nagesh Kumar Sep 07 '14 at 05:59
  • what i need is what usually JSF developers do when they create CRUD application, because I am new i need to know the usual scope used in such situation. you are suggesting to use conversation scope or to set the values after edit to null. but is it what JSF developers usually do? – user1512999 Sep 07 '14 at 06:10
  • You can use ViewScope if you use jsf 2.2 or higher. – Hosein Masbough Sep 07 '14 at 06:11
  • viewscope is used for the same page, but in my case I have one page for edit and another for addition – user1512999 Sep 07 '14 at 06:13

0 Answers0