wood burning stoves 2.0*
The moose likes Struts and the fly likes Getting null if i do not do an explicit new TestBean() in Action Class ..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting null if i do not do an explicit new TestBean() in Action Class ....." Watch "Getting null if i do not do an explicit new TestBean() in Action Class ....." New topic
Author

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

Rohit Rai
Ranch Hand

Joined: Aug 04, 2008
Posts: 53
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 04, 2008
Posts: 53
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

Joined: Sep 29, 2008
Posts: 12617

Unless there's a direct path to the method, how could it?
Rohit Rai
Ranch Hand

Joined: Aug 04, 2008
Posts: 53
Not sure what you mean by - a direct path to method
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How would Struts know which test() method to call unless it's explicitly stated somehow?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Getting null if i do not do an explicit new TestBean() in Action Class .....