Announcement Announcement Module
No announcement yet.
Inheritance annotation and RequestMapping problems Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inheritance annotation and RequestMapping problems

    I'm having a problem and I cannot find a solution for it. This problem is making me sick for the past few days. This is the model I use:

    @Inheritance(strategy = InheritanceType.JOINED)
    public abstract class UitlegOnderdeel {
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	@Column(name = "id")
    	protected Long id;	
    	 * Titel van het onderdeel
    	protected String naam;
    public class UitlegOnderdeelHTML extends UitlegOnderdeel {
    	String content;
    	public UitlegType getType() {
    		return UitlegType.HTML;
    When I call the next function from the browser, it prints null. The reason why is that Spring does not understand that a UitlegOnderdeelHTML is also a UitlegOnderdeel (which is abstract).

    @RequestMapping(value = "/admin/uitlegonderdeel/{onderwerpid}/form", method = RequestMethod.POST)
    public String create(@PathVariable("onderwerpid") Long onderwerpId, UitlegOnderdeel formObject, BindingResult result, ModelMap modelMap) {
    I have tried several things, like custom validation, type casting, but they all do not work since Spring does not bind the form to the formObject parameter.

    I am looking for a generic solution where I can use the method above (in some way) to bind several subclasses of UitlegOnderdeel. SpringMVC3 is used.

    Last edited by basilfx; Jul 4th, 2011, 10:37 AM.

  • #2
    And how should it know? You pass in an id (onderwerpid) and then you expect spring to automagically detect that that maps to a UitlegOnderdeelHTML? Next to that you are missing the @ModelAttribute if the object is your formObject without it is never going to do binding. However your method seems to be somewhat contra-dictionary.