• 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

using form bean in struts 2

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to do the following:

1) I have an online form with 20 fields in it. On click of submit button, the form values should be saved in to the database.
2) I have created a jsp file.
3) Created a form bean Employee.java with getters and setters method.
3) Created an action class which contains Employee as a variable, getter and setter method. getEmployee(), setEmployee(emp)


My Action class:



My jsp page:


Employee.java


it is showing null pointer exception at empInfo.getEmployeeId().

it is not setting the fields in Employee.java .
Am i doing anythign wrong??
Please help.
Its urgent

Thanks
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This is wrong. The field in your Action is named empInfo so you should' use



Same is applicable everywhere that you use EmployeeInfo in your JSP...
 
Deeps Mistry
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is wrong. The field in your Action is named empInfo so you should' use



Same is applicable everywhere that you use EmployeeInfo in your JSP...

Hey...what if i want to use the EmployeeInfo to display the values in jsp?

i tried the following:
<s:textfield value="" name="empInfo.EmpLastName" labelposition="left" value="%(empInfo.EmpLastName)"/>
also

<s:textfield value="" name="empInfo.EmpLastName" labelposition="left" value="%(empInfo.EmpLastName.toString())"/>

but didnt work

Please help me out!!!
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deeps, if you quote what someone wrote, you should use the [ quote ] tags which you can insert using the quote button on the screen where you enter your message.



Why are you having to set the value explicitly. If there is any value in empInfo.EmpLastName, then it will automatically get set in the text-field. Try using empInfo.empLastName instead of empInfo.EmpLastName (this is my fault )...
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am also having the same example .
Even though if I use "empInfo.empLastName" instead of "empInfo.EmpLastName", I still get the NullpointerException.
Please help me
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Remove the attribute value from textfield, if you want to display value back in screen, that time use value attribute.
 
pooja par
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.. it's working
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I do have the same problem. When I submit the JSP, the values are coming as null on the action class. Can someone help me, please.

LoginAction.java


LoginBean.java


Login.jsp


struts.xml


The below log statement has to print the value, I have entered on Login.jsp.

But, LoginBean is always null. Could you someone help me please, its urgent.





 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic