I extends
public class RenamingProcessor extends ServletModelAttributeMethodProcessor {
@Override
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest nativeWebRequest) {
...
binder.getObjectName();
...
}
}
Can binder.getObjectName()
returns null?
I tried to research source but I didn't find this information in javadoc?
No, it can't return null (in this statement i assume spring framework is not broken).
First off, WebDataBinder will always have a value. Looking at the ServletModelAttributeMethodProcessor implementation of bindRequestParameters they use
WebDataBinder binder
as is :It does not matter which constructor is used to build the WebDataBinder which you receive. Of the 2 available on WebDataBinder:
The second is obvious will have an objectName - in the sense that i don't believe any sane programmer working on spring will call this with a null value.
The first one calls the DataBinder constructor which calls the constructor with the objectName ( public DataBinder(Object target, String objectName)), except with a default objectName:
which is
There is no setter for the objectName. Once initialized, it will keep having a value.
Sidenote: the target attribute (
getTarget()
) can have a null value if the the binder is just used to convert a plain parameter value. Not sure about the application for this tho.Update: This answer cleared up my question on How is Spring's DataBinder used to convert a plain parameter value.