-
Jul 31st, 2008, 11:11 AM
#1
bind values after bind errors
Hi everybody,
I am having some trouble with a strange binding issue - I have an html lable element and a form:input element both maped to the same object property.
The label element gets its contents using a variable defined in a foreach loop on an object's path and an ${variable}, and the form:input is bound to the same path.
The issue is that in case there were bind errors (the user submitted false information that a property editor could not parse), the form:input field displays the information the user tried to submit but was not successfully bound, BUT the label element displays the last successfully bound information.
Is this behaviour expected? Do some methods of binding return the last succesfully bound info and some return the last info that was submitted?
thanks!
-
Jul 31st, 2008, 12:40 PM
#2
I can say that is odd, maybe the variable used in the label wasn't updated (in the controller) and that's the reason because is showing the old values.
In my case what I do is refresh the variables just returning the command object with the wrong values so the view can be able to get that.
As you say this behavior isn't normal, there should be one variable outdated.
-
Aug 3rd, 2008, 01:24 AM
#3
Hi,
thanks for the reply. This may very well be the case.
How may i update the variables in the controller (i am fairly new to spring and could not find any reference to the issue).
thanks again.
-
Aug 3rd, 2008, 03:45 AM
#4
I think this is expected behaviour because you will be referencing two different fields. Let me explain...
When you submit data that fails binding then the command object will not be updated with the new values since type conversion has failed. This makes sense, because if say you submitted text instead of a number, and your command object declared an int field, then what would it be updated to?
Spring will expose the incorrect data when redisplaying the view. This allows the view to re-display the incorrect data the user inputted and allows them to correct it. The form tags are displaying this data.
Now, I suspect when you retrieve the value for the label you are using the command object to access the value. This has NOT been updated since the binding fails, and hence you get the last correct value displayed.
So, to ensure they match up, you shouldn't use the command object directly, instead you need to retrieve the label using the <form:label> tag, or alternatively the <spring:bind> tag.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules