my dog learned polymorphism*
The moose likes Struts and the fly likes using form bean in struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "using form bean in struts 2" Watch "using form bean in struts 2" New topic
Author

using form bean in struts 2

Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189
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

Joined: Aug 03, 2008
Posts: 9280
    
  17



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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Deeps Mistry
Ranch Hand

Joined: Jan 31, 2009
Posts: 189

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

Joined: Aug 03, 2008
Posts: 9280
    
  17

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

Joined: Feb 14, 2011
Posts: 31
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

Joined: Jun 28, 2007
Posts: 53


Remove the attribute value from textfield, if you want to display value back in screen, that time use value attribute.
pooja par
Ranch Hand

Joined: Feb 14, 2011
Posts: 31
Thank you.. it's working
Santhosh Kalisamy
Ranch Hand

Joined: Apr 15, 2008
Posts: 56
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.





 
Consider Paul's rocket mass heater.
 
subject: using form bean in struts 2
 
Similar Threads
Struts 2 convertion type
spaces while populating using s:iterator
form bean is not getting updated upon submit in jsp
When Validation Error I Lose My Bean Value-Struts 2