Results 1 to 2 of 2

Thread: Inheritance annotation and RequestMapping problems

  1. #1
    Join Date
    Jul 2011
    Posts
    1

    Unhappy 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 at 09:37 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •