Instance variable increment in bean on button click JSF 2.2

584 views Asked by At

My xhtml file has a command button as so :-

<h:commandButton id="routeAddButton" action="#{routeStatic.add_new_route}" value="Add New Route" />

I am trying to control the visibilty of panelGrids using a boolean array.

<h:panelGrid id="route1Grid" columns="2" rendered="#{routeStatic.rendered[0]}" >

likewise

<h:panelGrid id="route2Grid" columns="2" rendered="#{routeStatic.rendered[1]}" >

and so on.

On each button click I am trying to increment a loop iterator(which is an instance variable) and successively set that panelGrid to be visible.

The instance variable is private int number_of_routes;

The Instance variable is initialized in the constructor to 0.

Now in my JSF Bean I have a method add_new_route() in which I want to do this:

    System.out.println(this.number_of_routes);
    this.rendered[this.number_of_routes]=true;
    this.number_of_routes++;

However in my log, I am repeatedly getting the value as 0. I understand primitive types are passed as reference. So I decided to use a singleton array. Still no good. Any ideas people?

1

There are 1 answers

0
Kesavacharan On BEST ANSWER

Is your bean request scoped ? In that case the variables will be created again after each click