Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting null if i do not do an explicit new TestBean() in Action Class .....

 
Rohit Rai
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my action class e.g. A



if in the JSP i have some code like

And if the TestBean is as follows



However if I remove then i get a NUll Pointer @



if in the JSP i have some code like

And if the TestBean is as follows



Whats wrong with the above code .... m missing something but i do not know what ??? Helpppp
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's missing is any link from the form element names on the JSP to action properties: if you're not implementing ModelDriven and providing the TestBean as the model, "name" and "roll" (I think you mean "role", by the way, unless it's specifically a bakery ordering system) there's no properties available on the stack named "name" and "roll".
 
Rohit Rai
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
Thanks a lot for the reply ... it was a silly mistake on my part there were two getters and setters with the same name in diferrent beans. e.g.


as soon as i renamed the getters and setters appropriately it started working fine.

One thing though i am confused as to why this happens .. its in a diferrent after all .. is struts not able to figure out which getter or setter to call ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless there's a direct path to the method, how could it?
 
Rohit Rai
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean by - a direct path to method
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would Struts know which test() method to call unless it's explicitly stated somehow?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic