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

  • Home
  • SEARCH
  • 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 3699300
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:05:10+00:00 2026-05-19T05:05:10+00:00

INITIAL QUESTION (UPDATED BELOW) I’m using an AutoPopulatingList list to instatiate an object invoking

  • 0

INITIAL QUESTION (UPDATED BELOW)

I’m using an AutoPopulatingList list to instatiate an object invoking a constructor with some parameters. Something like the code below. I had used it before without any problems but I can’t get it working now.

public class Tree {
    ...
    private List<Node> nodes = new AutoPopulatingList<Node>(new ElementFactory<Node>() {
        @Override
        public Node createElement(final int index) throws ElementInstantiationException {
             //call custom controller
             return new Node(index, ...other params);
        }       
    });
    ...
    //getters & setters
}

The object is mapped in a controller as a model attribute param (@ModelAttribute Tree). So I send in the form values like:

nodes[0].field1 = some value
nodes[1].field2 = other value

But when I send these parameters spring cannot instantiate the Node object because it’s looking for a constructor without params for Node object, and it throws an Exception like the following:

org.springframework.beans.NullValueInNestedPathException: Invalid property ‘nodes’ of bean class […Node]: Could not instantiate property type […Node] to auto-grow nested property path: java.lang.InstantiationException: …Node.()

If I add a constructor without params to Node class there is no error, but when I send nodes[0] it is invoked Node() instead of using the ElementFactory provided.

The weird thing is that if I do in the controller treeObject.getNodes().get(0), the constructor invoked is the one with params (as it should be).

I’m using Spring 3.0.4.RELEASE.

Does anybody knows why can this be happening? Can this be a bug?

Thanks.


UPDATE

I have build a custom implementation of a List similar to AutoPopulatingList to check if this was a problem of AutoPopulatingList, but it happens the same behaviour.
The implementation just overrides:

public Node get(int index) {
    //here just creates the object it it doesn't exist in the position
}

So the problem is why when I do in a controller:

public String controllerMethod(
@ModelAttribute Tree tree, BindingResult result, Model model){
     ...
}

and I send nodes[0].something as there isn’t any object in the position 0 of index it has to instance the object. But the problem is that it is invoked Node() constructor before invoking tree.get(0). So, Why does Spring invokes the default constructor? How can I force it to use tree.get(0) to instance the object instead of Node()?

  • 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-05-19T05:05:10+00:00Added an answer on May 19, 2026 at 5:05 am

    I’ve solved it by disabling the autogrownestedpaths in the binder, so this allows Autopopulating list will take care of auto-growing with its own factory.

    @InitBinder
    public void initBinder(WebDataBinder binder){
        binder.setAutoGrowNestedPaths(false);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ModelMultipleChoiceField doesn't select initial choices and I can't make the following fix (link below)
I would like to set some initial variables (like format compact and the current
I am using SVN to develop some software in a team of four people.
This question have been answered. I recommend sumit_programmers solution below. For now, I've removed
I am using the code below to do pagination on a table (please do
Question : What is the recommended way to specify an initial value for fields
Initial Problem I was using yaml_db in a Rails project, but it seems the
this is my first question here @stackoverflow. I'm writing a monitoring tool for some
When prototyping initial GUI functionality with a customer is it better to use a
During our initial development we haven't worried about scaling concerns, just getting the bare

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.