0

I want to add +1 every time a method runs, and then show it in an outputText, but this just add another 0 beside the existing one every time the method runs, what can I do to fix this?

BEAN

private int count=0;

//constuctor

public void doSomething(String asnwer){

 count++;
... 
}
//setters and getters

JSF page

<p:panelGrid id="ver">
            <h:outputText value="#{bean.count}"/> //getter for the count
</p:panelGrid>

<p:commandButton value="Japan" action="#{bean.doSomething(japan)}" update="ver" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
DedalusNine
  • 47
  • 1
  • 8
  • Try aspect oriented programming to implement this. You don't want this kind of logic mixed into your business logic. – Vince Jul 07 '16 at 19:14
  • What you have posted is not a bean. It is just a variable and a method, not a bean. So post a complete bean implementation with the corresponding annotation. – ujulu Jul 07 '16 at 19:56
  • ujulu...It is called "Abstraction", as a programer you should know it. – DedalusNine Jul 07 '16 at 20:13
  • As a programmer you should know that the information you provided is not enough to define a jsf bean :-) – ujulu Jul 07 '16 at 20:21
  • Im just a music teacher trying to make apps for my students....its sessionScoped by the way. – DedalusNine Jul 07 '16 at 21:00

1 Answers1

1

Making the count variable static can solve your problem.

ChiTraN
  • 19
  • 2