Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8507377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:51:16+00:00 2026-06-11T02:51:16+00:00

I am not sure if this is a complex problem but as a starting

  • 0

I am not sure if this is a complex problem but as a starting person this seems a bit complex to me.
I have an object based on which i need to show some values on the UI and let user select some of them, i need to send data back to another controller when user click on the submit button.Here is the structure of my data object

public class PrsData{
private Map<String, List<PrsCDData>> prsCDData;
}

public class PrsCDData{
  private Map<String, Collection<ConfiguredDesignData>> configuredDesignData;
}

public ConfiguredDesignData{
  // simple fields
}

I have set the object in model before showing the view like

model.addAttribute("prsData", productData.getPrData());

In the form i have following settings

<form:form method="post" commandName="prsData" action="${addProductToCartAction}" >
<form:hidden path="prsCDData['${prsCDDataMap.key}']
  [${status.index}].configuredDesignData['${configuredDesignDataMap.key}']
  [${configuredDesignDataStatus.index}].code"/>

<form:hidden path="prsCDData['${prsCDDataMap.key}']
  [${status.index}].configuredDesignData['${configuredDesignDataMap.key}']
  [${configuredDesignDataStatus.index}].description"/>

</form:form>

This is what i have at AddProductToCartController

public String addToCart(@RequestParam("productCodePost") final String code,
@ModelAttribute("prsData") final PrsData prsData, final Model model,
@RequestParam(value = "qty", required = false, defaultValue = "1") final long qty)

On submitting the form i am getting following exception

org.springframework.beans.NullValueInNestedPathException: Invalid property 'prsCDData[Forced][0]' 
of bean class [com.product.data.PrsData]: 
Cannot access indexed value of property referenced in indexed property path 'prsCDData[Forced][0]': returned null

It seems like its trying to access the values on this controller while i am trying to send value to that controller and trying to create same object with selected values

Can any one tell me where i am doing wrong and what i need to take care of

Edit

I did some more research and came to know that Spring do not support auto-populating list/map for custom objects and based on the answer i tried to change implementation like

public class PrsData{
    private Map<String, List<PrsCDData>> prsCDData;
    // lazy init
    public PrsData()
    {
           this.prsCDData = MapUtils.lazyMap(new HashMap<String, List<PrsCDData>>(),
                FactoryUtils.instantiateFactory(PrsCDData.class));
        }
    }

    public class PrsCDData{
      private Map<String, Collection<ConfiguredDesignData>> configuredDesignData;
      public PrsCDData()
    {

       this.configuredDesignData = MapUtils.lazyMap(new HashMap<String,  
                                      List<ConfiguredDesignData>>(),
            FactoryUtils.instantiateFactory(ConfiguredDesignData.class));

    }
    }

but i am getting following exception

org.springframework.beans.InvalidPropertyException: 
Invalid property 'prsCDData[Forced][0]' of bean class [com.data.PrsData]:
Property referenced in indexed property path 'prsCDData[Forced][0]' 
is neither an array nor a List nor a Set nor a Map; 
returned value was [com.data.PrsCDData@6043a24d]

i am not sure which thing i am doing wrong, it seems that either my JSTL expression is not right

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:51:18+00:00Added an answer on June 11, 2026 at 2:51 am

    Explanation : if in you controller you have @ModelAttribute("user") User user, and you load a corresponding page that contains <form:form commandName="user">, an empty User is instantiated.

    All its attributes are null, or empty in case of a List or a Map. Moreover, its empty lists/maps have been instantiated with an autogrowing implementation. What does it mean ? Let’s say we have an empty autogrowing List<Coconut> coconuts. If I do coconuts.get(someIndex).setDiameter(50), it will work instead of throwing an Exception, because the list auto grows and instantiate a coconut for the given index.
    Thanks to this autogrowing, submitting a form with the below input will work like a charm :

    <form:input path="coconuts[${someIndex}].diameter" />
    

    Now back to your problem : Spring MVC autogrowing works quite well with a chain of objects, each containing a map/list (see this post). But given your exception, it looks like Spring doesn’t autogrow the possible objects contained by the autogrowed list/map. In Map<String, List<PrsCDData>> prsCDData, the List<PrsCDData> is a mere empty list with no autogrowing, thus leading to your Exception.

    So the solution must use some kind of Apache Common’s LazyList or Spring’s AutoPopulatingList.
    You must implement your own autogrowing map that instantiates a LazyList/AutoPopulatingList for a given index. Do it from scratch or using some kind of Apache Common’s LazyMap / MapUtils.lazyMap implementation (so far I have not found a Spring equivalent for LazyMap).

    Example of solution, using Apache Commons Collections :

    public class PrsData {
    
      private Map<String, List<PrsCDData>> prsCDData;
    
      public PrsData() {
          this.prsCDData = MapUtils.lazyMap(new HashMap<String,List<Object>>(), new Factory() {
    
              public Object create() {
                  return LazyList.decorate(new ArrayList<PrsCDData>(), 
                                 FactoryUtils.instantiateFactory(PrsCDData.class));
              }
    
          });
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex problem and I am not sure what is causing it.
I have in mind a design problem that does not look like complex, but
I'm not sure if this is even possible, but here goes: I have a
Not sure this is possible, but looking to write a script that would return
I'm not sure this is even possible but I know if it is, the
I'm not sure this is possible, but in ruby, you can dynamically call a
I'm not sure this is possible, but is there a syntax to be used
I'm not sure this question is appropriate here but I hope I could get
I have following complex query which I need to use. When I run it,
I'm not sure if it's possible to give general advice on this topic, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.