1

I am out of ideas and turning to the community experts. I am using Hibernate Single table inheritance which is driving me in this direction.

I have a BaseEntity class with many Subclasses using a Discriminator. I am using Spring MVC annotated controllers for the CRUD operations and JSPs using Spring form tags for the view.

I have a backingForm which includes the subclassed entities that the form uses. To save a ton of duplicate code I have a common.jsp that contains the fields in the BaseEntity and then other JSPs specfic to each subclasses.These other JSPs include the common.jsp. I am able to display the data fine by looknig at a pathVariable and then loading the proper subclass, adding it to the form. Form submission and Spring's DataBinding has got me reeling. Can any suggest a good way to allow for Spring to dymanically post to a specific nested property. Think about it like using polymorphism on a form submission. I know the may seem confusing, but idf anyone has ever tried this it should make perfect sense :-). This is not about dynamic list binding (AutoPopulating) this is very different.

Thanks for any insight at all.

1 Answer 1

1

Within your annotated controller you can do as a separate method:

@ModelAttribute("backingObject")
public SuperClass getBackingObject(HttpRequest request //etc) {
  //determine value of your path variable
  //create appropriate subcass
  return subClassInstanceForBinding;
}

So then when spring goes to bind it will find "backingObject" in the model map that you put there and use it, rather than looking for a constructor.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I will look into doing this. Also, I think I may have found another way by using a variable in spring's form tag. I can use the forms's tag "path" with a variable like this: <form:input path="${someVariable}.field" />. THis allows dymanic binding. I am seeing some early success so far.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.