java - How to get ActionForm in Struts2? -
i migrating struts 1 app struts2 , trying minimize code changes required. need know how access actionform
in struts2 action class. below current code , getting npe when trying access actionform
.
public class deptbuildingnewaction extends actionsupport implements servletrequestaware, servletresponseaware, modeldriven<deptbuidingformbean> { private httpservletrequest request; private httpservletresponse response; private deptbuidingformbean form; public void setservletrequest(httpservletrequest httpservletrequest) { this.request = httpservletrequest; } public void setservletresponse(httpservletresponse httpservletresponse) { log.debug("inside setservletresponse"); this.response = httpservletresponse; } public deptbuidingformbean getmodel() { log.debug("inside getform"); return form; } public void setmodel(deptbuidingformbean form) { log.debug("inside setform"); this.form = form; }
what best way actionform
on here ? thank time.
the form (model in struts2) should initialized prevent npe.
private deptbuidingformbean form = new deptbuidingformbean();
the modeldriven
action allows access model on view layer , in action directly value stack, i.e. without model
or form
prefix. modeldriven
interceptor should on interceptors stack of action. default stack contains interceptor.
from docs:
note: modeldriveninterceptor push model stack when model not
null
, else ignored.
in action class have field can use inside.
Comments
Post a Comment