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>