0
votes

I have a question. If I want to display on start in h:inputText a "default value" should i do second getter with default value? for ex.: my entity has field:

private int yellowCards;

public int getYellowCards() {
    return yellowCards;
}

public void setYellowCards(int yellowCards) {
    this.yellowCards += yellowCards;
}

in db there is 3 yellow cards. Now I want to add another stats for this Entity - next yellow card. but I don't want to have in inputText on view "3" but default "0". Is there something way to set "default" value of this field or only add second getter for this view?(because in other view i need to use this first getter to display all stats).

2
You can initialize java managed bean fields in three ways : at definition, in constructor(s) or in the @PostConstruct annotated method(s) - The Bitman

2 Answers

0
votes

Use the the callback method of the bean : @PostConstruct, this will allow you to do the stuff before the page gets rendered :

private int yellowCards;

@PostConstruct
public void init(){
    yellowCards = 0;
}

// getter/setter
0
votes
@Field
private int minutesPlayed;     
@Transient
private int STATminutesPlayed;

public int getSTATminutesPlayed() {
    return 90;
}

public void setSTATminutesPlayed(int STATminutesPlayed) {
     setMinutesPlayed(STATminutesPlayed);
}
public int getMinutesPlayed() {
    return minutesPlayed;
}

public void setMinutesPlayed(int minutesPlayed) {
    this.minutesPlayed += minutesPlayed;
}

I think is the best way to do it. STAT field and getter/setter for adding stats, and minutesPlayed with getter/setter for future display all of stats and alternatively edit them in other view.