Announcement Announcement Module
No announcement yet.
Null Object reference in form:select path value Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Null Object reference in form:select path value

    I have a command object (AssetCommand) that contains a rich object (asset). On my form the user selects the assetType by choosing from a dropdown control. My problem occurs when the user is adding a new asset and the asset object is not yet set. When the page loads I get an error:

    "Invalid property 'asset' of bean class [com.xxxxx.AssetCommand]: Value of nested property 'asset' is null."

    my jsp code:
    <form:select id="assetType" multiple="false" path="asset.assetType">
    <form:option label="Select a value" value="" />
    <form:options items="${command.assetTypeList}" itemLabel="description" itemValue="name" />
    I can't populate an empty asset object prior to loading the view because the asset constructor takes the assetType.

    My question is, is there a way in Spring to handle this scenario? If not, what is the best way to handle this? It seems to me this would be a fairly common issue. I've done some searching on the forums and haven't found much information.

    Any help would be much appreciated.

    Last edited by sweetgoose; Sep 17th, 2008, 05:03 PM.

  • #2
    Why not initialize the asset property by using a null assetType? Since you are referring to the nested property within asset it has to be initialized.

    Please use [code][/code] tags next time.
    Last edited by maverickthinker; Aug 19th, 2008, 07:43 PM.


    • #3
      Sorry I wasn't clear enough in my original statement. An Asset object cannot be instantiated with a null AssetType. The AssetType is necessary during instantiation in order to populate a Map of Attributes.

      Is there no way in Spring to handle null object references in the form binding? I'm new to Spring, but this seems like it would be a common issue.