why does the validation phase call the managed bean getters?

I've read through the spec and can't find the answer, and it doesn't make sense. You are validating the data in the JSF tree, so why would you care what the managed bean has?

Here's my problem. I implemented my managed bean as a self-populating bean. I initialize all fields by calling a DAO bean inside the constructor. I get an ID parameter from the request that I pass to the DAO. And the scope for my bean is request, which is the key here.

So when I get a new request (with the parameter I expect), everything works fine. Then the user can modify the fields and save. But here comes the problem. Since I'm in request scope, a new bean is instantiated when they save, and since now there's no ID in the request, I get an empty bean. That's still OK, but then the process validation phase hits and it starts calling all my getters. For simple String fields it's fine, but for list boxes it's looking for an array of SelectItem objects, and it has to be of the same size, or I get a validation error.

So is there any way to get around this? Of course I could save the ID, and repopulate the bean from the DB, but the second hit would be for no reason. Using immediate is not an option, as I do want to validate, I just don't want validation to call my managed bean getters. Makes no sense to me why validation would call getters, especially in request scope.

[1396 byte] By [elbullaa] at [2007-10-2 5:30:27]
# 1

I little update. I found that a way to get around this problem is using myfaces <t:saveState/> tag. This tag will persist the request bean a little longer, but not as long as being in a session. I'm not sure of the exact mechanism, but the effect is that a new managed bean is not instantiated in the validation phase.

It seems to me that JSF should not attempt to instantiate a bean when processing validations for a request scoped bean. Maybe just an oversight.

elbullaa at 2007-7-16 1:41:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
> fbut for list boxes it's looking for> an array of SelectItem objects, and it has to be of> the same size, or I get a validation error. See the javadoc of validateValue() of UISelectMany or UISelectOne.
yuki.yoshidaa at 2007-7-16 1:41:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
sure, validateValue() says that the selected items should be a subset of the available ones. But the check should go against the component tree for that, not the managed bean. That bean doesn't exist in request scope!
elbullaa at 2007-7-16 1:41:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
> But the check should go against the component tree for that,> not the managed bean. Do you mean that value binding should not be dynamic but be static(be evaluated once only)?
yuki.yoshidaa at 2007-7-16 1:41:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Yes, at the very least have the option of not evaluating again. If working with a request scoped bean, and you have an expensive query to populate the bean, you don't want to take a double DB hit.
elbullaa at 2007-7-16 1:41:30 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...