Command Objects in Spring

前端 未结 2 742
一整个雨季
一整个雨季 2021-01-02 17:20

I have a command object composed of primitive fields and an object field. How do I bind my form fields to the fields in the object?

I tried doing this but to no ava

相关标签:
2条回答
  • 2021-01-02 17:45

    Your list either needs to be pre-populated with as many LearningActivity objects as you plan to refer to (using activity[0], activity[1], etc.) or it needs to be a lazy list. A lazy list is a list that will populate itself with empty objects when a given index is referenced.

    A comment indicates that you're trying to use Apache Commons LazyList, which ought to work -- are you missing an import directive? However, as an alternative there is a Spring lazy list implementation called AutoPopulatingList.

    0 讨论(0)
  • 2021-01-02 17:48

    Two possible issues here:

    1. activity.activity is invalid (unless your getters do not correspond to your member variables) because Course.activity is a list. You need to address a particular list element - e.g. activity[0].activity. You'll also have to make sure it actually exists.

    2. Have you configured your FormController correctly? Does it pass Course instance to view as it should? Take a look at Spring MVC tutorial for an example.

    If after you've fixed #1 and verified that #2 is done correctly the error doesn't go away, please post more details (FormController mapping / source).

    0 讨论(0)
提交回复
热议问题