Struts 2 Action Form bean
posted 12 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
posted 12 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Are you getting the NPE when the page is displayed (as opposed to when the form is submitted?)
Alps Sharma
Greenhorn
Posts: 7
posted 12 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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?
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?
posted 12 years ago
I assume this is when you are submitting this form. How are you displaying the form? Do you have a different action?
The code as you have it should work. Do you have a setAddressBean() method in employeeBean?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
posted 11 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 .
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 |








