2

Consider the following three classes, C is a subclass of B. B is a field of A. How to pass An instance of class A which contains an instance of class C as its field, from JSP pages to Spring Controller method?

class A{ private B b; public B getB(){return b;} public void setB( B b){ this.b = b;} } class B{ private int id; public int getId(){return id;} public void setId(int id){this.id = id;} } class C extends B{ private name; public String getName(){return name;} public void setName(String name){this.name = name;} } 

The sample Spring controller:

@Controller public class Handler{ @RequestMapping("/work") public String work(@RequestParam( "objA" ) A objA ){ if( C.getClass().isInstance( objA.getB() ) ){ System.out.println("It works."); } } } 

The supposed JSP page but doesn't work:

<form method="post" action="work" commandName="objA" > <input type="submit" value="submit" /><br/> <input type="hidden" name="b.name" value="name" /><br/> <input type="hidden" name="b.id" value="1" /><br/> </form> 

1 Answer 1

1

I think we can use Jackson to bind data. Then we can treat it as Jackson Polymorphic Type Handling Problem Here is a link about how to use Jackson and ajax in Spring mvc context.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.