• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what you mean by - a direct path to method
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would Struts know which test() method to call unless it's explicitly stated somehow?
 
reply
    Bookmark Topic Watch Topic
  • New Topic