Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using form bean in struts 2

 
Deeps Mistry
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
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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 )...
 
pooja par
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
 
selvaraju sellamuthu
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
 
Santhosh Kalisamy
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.





 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic