Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean property must has both getter / setter ?

 
Vince Hon
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In HFB P.368
2 The thing to the right of the dot MUST be a Map Key or a /*bean property*/



And in HFB P.350, the Bean law states that 4) The property name and type are derived from the getters and setters and NOT from a member in the class.


That mean if I have a bean called MyBean and property called pp: int, the MyBean class must have BOTH getter and setter for "pp".

In HFB P.15 Question 15



Will options A, B, D, E always print "nothing" since there are no those property (because no setter methods) ?
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It is not necessary to have both getter and setter methods. In the above case, the value can be assigned at the time of initialization.

thanks
 
Vince Hon
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

However, this qoute

And in HFB P.350, the Bean law states that 4) The property name and type are derived from the getters and setters and NOT from a member in the class.


The "bean requires both getter/setter" is apply to the <jsp:setProperty../> but not the EL ?
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think the getter/setter not only apply to the setProperty but for the EL also. When using . or [] it calls the getter method. In general if no setter , then the property is read-only. If only getter is definde, you can not update the property using setProperty. If there is no getter then there is error while accessing the property using getProperty or EL.
for the following declaration,
private int var;

it is not neccessary that the getter and setter should be

public int getVar()
public void setVar(int)

I can use

public int getVars()
public void setVars(int)

But in this case the property name for bean and EL purpose is vars not var, but the method logic can do anything and can return anything (of given type). It is not neccessary to define the variable int var at all.

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic