Announcement Announcement Module
Collapse
No announcement yet.
Inheritance annotation and RequestMapping problems Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
    @Entity
    @RooEntity
    @RooJavaBean
    @Inheritance(strategy = InheritanceType.JOINED)
    public abstract class UitlegOnderdeel {
    
    	@Id
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	@Column(name = "id")
    	protected Long id;	
    	
    	/**
    	 * Titel van het onderdeel
    	 */
    	@NotNull
    	protected String naam;
    }
    
    @Entity
    @RooEntity
    @RooJavaBean
    public class UitlegOnderdeelHTML extends UitlegOnderdeel {
    
    	@Lob
    	String content;
    
    	@Override
    	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).

    Code:
    @Transactional
    @RequestMapping(value = "/admin/uitlegonderdeel/{onderwerpid}/form", method = RequestMethod.POST)
    public String create(@PathVariable("onderwerpid") Long onderwerpId, UitlegOnderdeel formObject, BindingResult result, ModelMap modelMap) {
    	System.out.println(formObject);
    	...
    }
    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.

    -BasilFX
    Last edited by basilfx; Jul 4th, 2011, 09: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.

    Comment

    Working...
    X