This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes a simple question about Form Bean setter method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "a simple question about Form Bean setter method" Watch "a simple question about Form Bean setter method" New topic
Author

a simple question about Form Bean setter method

Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
In Form Bean's setter method, is there any "rule" we have to follow for naming convention ? for example, if I have a variable called "day_of_travel",

can I do

public void setDay_of_travel(...);

or

public void setDay_Of_travel(...);

or

public void setDay_Of_Travel(...);

If all of three methods work, then it seems there is no rule, then how does struts know when user enter that field which setter method it should use to fill the Form bean instance ?

thanks.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
According to the standard Java Bean naming convention, the following is correct:

public void setDay_of_travel(...);

Of course, in Java, the variable would normally be named...

dayOfTravel

...and therefore have a corresponding setter of:

setDayOfTravel(...);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: a simple question about Form Bean setter method
 
Similar Threads
NoSuchMethodError
javabean getter and setter
<jsp:useBean> example
Will the setters be called
Pre-select collection of options (drop-downs)