• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Struts 2 Action Form bean

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am new to Struts2. I have a requirement where i am mapping a Employee bean with Action and Employee bean further contains fields like firstname, last name and a further bean i.r address bean.I am not able to get the value of nested bean in action class.

Following is the brief code to explain the scenario


IN JSP :

I am getting the correct value for firstName and lastName in action class but if i try to access employeeBean.addressBean.address1 , i am getting null pointer exception.Can anyone tell me what changes i need to make to get the value.

I tried to print address1 value by employeeBean.getAddressBean().getAddress1() in Action class.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you getting the NPE when the page is displayed (as opposed to when the form is submitted?)
 
Alps Sharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not in jsp page .. but i tried to debug the value using debugger ,its showing the value of addressBean as null and when i tried to access the value in Action class using employeeBean.getAddressBean().getAddress1() i am getting NPE However i am getting the value of other fields of EmployeeBean.

Actually as per requirement i need to get this value in Action and perform some logic there.Is there any way i can map the value of nested bean fields with text box?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alps Bandhu wrote:,its showing the value of addressBean as null and when i tried to access the value


I assume this is when you are submitting this form. How are you displaying the form? Do you have a different action?

Alps Bandhu wrote:Is there any way i can map the value of nested bean fields with text box?



The code as you have it should work. Do you have a setAddressBean() method in employeeBean?
 
Alps Sharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for replying so late .Setter methods were there. The problem occurred because i missed adding the default constructor in EmployeeBean.
After adding default constructor it worked .
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic