开发者

Getter and Setter - POJO object - Problem with input data in Struts2

开发者 https://www.devze.com 2022-12-16 23:40 出处:网络
I have a problem with setter and getter method in struts2. I have a form : ... +all input fields of job/>

I have a problem with setter and getter method in struts2. I have a form : ... + all input fields of job/>

and action: (addJob is mapped at this action) public class InsertJobAction extends ActionSupport{ ... private Job job = null; public String execute(){ jobService.insert(job); //here job is not null; that is ok }

  • getter and setter for job }

this action works correctly;

I have a similar form and action, but the input fields from thisform are less than first form; The problem is here: in execute() of the second action job is null. Why?? Does depend it of fields noumber ?? I have 2 constructors in my Job class one with no params, and one with all params for every field of class;

I made debug with Log4j ...and in first case there arrives in Job constructor in the second not. Why??When it calls constructor???

When are called the setter开发者_如何转开发 and getter methodsb, before or after execute() method??? And when i have a form with input data?? Are called setter methods before execute() method?

I'm very confusely because in a case it works without problems, but in the second case it doesn't

Thanks, Andrew


I am assuming you are using session to store data and the data in the setters require a valid bean pulled from the session.

Based on the action states the order in which the methods are called. For example the constructor is not called the first time the POJF is run, however the second pass does. Also if you are submitting form data then the execute will only run once the data has been processed. See the following for a basic stack trace of calls based on actions.

Call Stack
## First Time Run ##
execute()
getTodayDate()
getTodayDate()
getTomorrowDate()
getTomorrowDate()
getBirthDate()
getBirthDate()
getDesc()

## Second Pass ##
DateBeanAction()
setSession(Map session)
execute()
getTodayDate()
getTodayDate()
getTomorrowDate()
getTomorrowDate()
getBirthDate()
getBirthDate()
getDesc()

## Submit ##
DateBeanAction()
setSession(Map session)
setBirthDate(Object birthDate)
setTodayDate(Object value)
setTomorrowDate(Object value)
setDesc(String desc)
execute()
getTodayDate()
getTodayDate()
getTomorrowDate()
getTomorrowDate()
getBirthDate()
getBirthDate()
getDesc()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号