开发者

when setXXXX("argument") method called in form.java of struts framework?

开发者 https://www.devze.com 2023-01-31 06:26 出处:网络
When setXXXX(\"argument\") method is called in form.java of struts framework? We ju开发者_开发技巧st call getXXXX() in action but I want to know when the setXXXX(\"argument\") method is called?Getter

When setXXXX("argument") method is called in form.java of struts framework?

We ju开发者_开发技巧st call getXXXX() in action but I want to know when the setXXXX("argument") method is called?


Getters are usually called to retrieve data in the view (for instance a JSP file) while setters are used to insert the data from the view. The setters are called when you populate data from a form. So if you send in your form a value with name "property1" with value "myValue1" it will call the getter getMyProperty1("myValue1").

In case you use nested objects it will call the getter on the object and then a setter on the property. For example if you have a user object of Type User and the user has an attribute called "username" you can send in your form a value with name "user.username" with value "value of the user". So first it will invoked the getter to get the User object and then on this object it will be called setUsername("value of the user").

Setters are nnot compulsory if you donb't provide them you won't allow to change this value from the view.

0

精彩评论

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