• Post Reply Bookmark Topic Watch Topic
  • New Topic

Validation order when managed bean scope is request  RSS feed

 
Humberto Santana
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody

I have a jsf page that with 2 lists. A list of dates and a list of people.

But the list of people depends on the chosen date.

I use ajax4jsf to update people list when date changes, and it works fine.

But when I click on save button I get "Validation Error: Value is not valid" on people list.

It happens because validate tries do call people list before (or without) calling date list. As date list is null, the form gets the default value for date (not the chosen date). And with the wrong date, people list does not have the person I chose. That's why I get Validation Error.

When I put the managed bean on session it works. But I don't wanna do this.

Is there a way to force validation to call a method before validate?

Or, Is there a better way to do this?

Thanks in advance


 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When your listener sets up the new people list, null out the currently selected person property. That will cause the UI to render with the default person selection (which I usually make be "-- Select a Person --"). Since you're no longer referencing a value that's not in the (updated) selection list, and a null property is OK for output, that fixes your problem.
 
Humberto Santana
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

But the main problem is that even date list becomes null when I click on save button. So validation puts default value on date instead of chosen date.

I realized this problem when I put a breakpoint on getPeopleList and getDateList methods. Break point stops on getPeopleList and not on getDateList.

If validate was calling getDateList before getPeopleList I think it would work.
But since validate call getPeopleList first, the list of dates is null and chosen date is default. So, chosen person is without peopleList since it depends on chosen date.

When iI put managed bean on session scope it works because validation does not have to rebuid the list.

But I don't want to put managed bean on session.

Sorry for my bad english. I hope you understand.

Thanks in advance
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!