Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

using form bean in struts 2

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • 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: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank you.. it's working
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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.





 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic