Reputation: 169
Hi I am trying to set a default value 00 for a field in domain file that contains getters and setters.
When no data is inserted, it should have a value of 00.
private String tapeStartHour;
public String getTapeStartHour() {
return tapeStartHour;
}
public void setTapeStartHour(String tapeStartHour) {
this.tapeStartHour = tapeStartHour;
}
But I dont know where I should put
set value='00'
Can anyone help?
Upvotes: 0
Views: 1284
Reputation: 600
Try this-
private String tapeStartHour;
public String getTapeStartHour() {
if(tapeStartHour == null)
setDefault();
return tapeStartHour;
}
public void setTapeStartHour(String tapeStartHour) {
if(tapeStartHour == null)
setDefault();
this.tapeStartHour = tapeStartHour;
}
private void setDefault() {
tapeStartHour = '00';
}
Upvotes: 0
Reputation: 5187
Simply using:
private String tapeStartHour ="00";
public String getTapeStartHour() {
return tapeStartHour;
}
public void setTapeStartHour(String tapeStartHour) {
this.tapeStartHour = tapeStartHour;
}
P.S. You cannot use ''
notation. It is used for char
. For String
you have to use ""
notation.
Upvotes: 0
Reputation: 150
Set the value on the declaration:
private String tapeStartHour = "00";
Or, on your getter:
public String getTapeStartHour() {
return tapeStartHour.equals("") ? "00" : tapeStartHour;
}
Upvotes: 1