【发布时间】:2015-06-16 17:50:43
【问题描述】:
我的 xhtml 文件有一个命令按钮:-
<h:commandButton id="routeAddButton" action="#{routeStatic.add_new_route}" value="Add New Route" />
我正在尝试使用布尔数组来控制 panelGrids 的可见性。
<h:panelGrid id="route1Grid" columns="2" rendered="#{routeStatic.rendered[0]}" >
同样
<h:panelGrid id="route2Grid" columns="2" rendered="#{routeStatic.rendered[1]}" >
等等。
在每个按钮单击时,我都试图增加一个循环迭代器(它是一个实例变量)并连续将该 panelGrid 设置为可见。
实例变量是private int number_of_routes;
Instance变量在构造函数中初始化为0。
现在在我的 JSF Bean 中有一个方法 add_new_route() 我想在其中执行此操作:
System.out.println(this.number_of_routes);
this.rendered[this.number_of_routes]=true;
this.number_of_routes++;
但是在我的日志中,我反复将值设为 0。我知道原始类型是作为参考传递的。所以我决定使用单例数组。还是不行。有什么想法吗?
【问题讨论】:
标签: java xhtml increment jsf-2.2 instance-variables