Friday, May 3, 2013

Resolving Neither BindingResult nor plain target object issue

The common error stack we observe when we are working with spring tag library is 'Neither BindingResult nor plain target object for bean name available as request attribute'. 

The error message itself explaining that we have not mentioned the corresponding command object details (command name, command class).

When we face this problem:

When we are using forms in our application, in general we will use tag library provided by spring

i.e, 

As part of the  spring tag library we have tag's to use different html components as part of our application (like form, textfiled,checkbox .. etc).

Here is the sample code ..


Here we have not mentioned the commandName attribute as part of form tag, which means we have not provided the details of command object.

one more case we may observe .,


In the spring-servlet.xml we have configured our class SaveDataController with all required properties except commandName. This is the other case where we used to get the same error.

How to Resolve this :

The solution to the above mentioned problem is so simple. We need to provide command object details in order to avoid this error.

Here is the solution



We have provided commandName attribute for the  and



here we have provided the commandName property for the SaveDataController class.


That's it. Remember , We need to cofigure everything as part of our xml files and in case of forms we need to provide commandName and commandClass

Special Case:

For e.g i have a form without any fields and only have button (ofcourse, in general we may not face this situation , form without input fileds)


Here we have used only button within the form. In this case we don't need any command class.

As command class is used to get the data from the form and store that collected data from the form into command object and here we don't have any input fileds to collect the data entered by user. That's why we no need to provide command object details.


No comments:

Post a Comment