In have a custprofileview
Action which show a JSP page with all details of customer and in my JSP all fields are like my
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
and do so on, and there is a submit button that calls Action updatecustprofile
.
In updatecustprofile
Action, instead of directly mapping properties I have a member variable private CustprofileVO custprofileVO;
with setter and getter.
In CustprofileVO
Class I have fields like email
, phone
and all other fields with their setters and getters methods.
Problem is: in updatecustprofile
Action I am implementing Prepareable
Interface, and in implementation of prepare()
method I have custprofileVO.setDefaultID("Select");
and setting 4 more fields but when I run the program by clicking on submit button I get NPE
in the very first line that is custprofileVO.setDefaultID("Select");
It looks like the framework is not instantiating CustprofileVO custprofileVO
. If I manually instantiate custprofileVO
just above setting of the field (by doing custprofileVO = new CustprofileVO()
then it works.
Problem is- ideally struts2 framework should give me instance which it is not doing, want to understand the reason.
Further if I manually set custprofileVO
in prepare method it works but I have also applied validation using XML where my field name is custprofileVO.email
,its validation then custprofileVO.phone
its validation.
When I try to validate on click of submit button validation runs but on screen I see messages for all fields as data in all textboxes gets blanked out.
Why is data getting removed ?