Getter 和 Setter - POJO 对象 - Struts2 中输入数据的问题

发布于 2024-08-18 21:53:26 字数 645 浏览 2 评论 0原文

我在struts2中遇到了setter和getter方法的问题。 我有一个表格: ... + 职位的所有输入字段>>

和操作:(addJob 映射到此操作) 公共类 InsertJobAction 扩展 ActionSupport{ ... 私人工作工作=空; 公共字符串执行(){ jobService.插入(工作); //这里的job不为null;没关系 工作的getter

  • 和 setter 这个动作可以

正常工作;

我有一个类似的表单和操作,但此表单的输入字段少于第一个表单; 问题就在这里:第二个操作作业的execute() 中为空。为什么?? 取决于字段编号吗? 我的 Job 类中有 2 个构造函数,其中一个没有参数,另一个则为类的每个字段都包含所有参数;

我用 Log4j 进行了调试...在第一种情况下,在第二种情况下到达了 Job 构造函数。为什么?当它调用构造函数时???

何时调用 setter 和 getter 方法b,在execute() 方法之前还是之后???当我有一个包含输入数据的表单时?在execute()方法之前调用setter方法吗?

我很困惑,因为在某种情况下它可以正常工作,但在第二种情况下则不然,

谢谢, 安德鲁

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扮仙女 2024-08-25 21:53:26

我假设您正在使用会话来存储数据,并且 setter 中的数据需要从会话中提取有效的 bean。

基于操作说明调用方法的顺序。例如,第一次运行 POJF 时不会调用构造函数,但第二次运行时会调用该构造函数。此外,如果您提交表单数据,则只有在处理数据后才会运行执行。请参阅以下内容,了解基于操作的调用的基本堆栈跟踪。

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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文