Say I have this piece of code
<p:dataTable styleClass="scheduleTable" value="#{todaySchedule.hours}" var="hour">
<p:column headerText="Hour" styleClass="hourColumn" >
#{hour.time}
</p:column>
</p:dataTable>
and in a class called todaySchedule, have a method
public List<Hour> getHours() {
final List<Hour> hours = IntStream.range(0, Hour.TIME.values().length)
.mapToObj($ -> new Hour()).collect(Collectors.toList());
for (int i = 0; i < 5; i++) {
hours.get(i).setHour(1);
}
return hours;
}
and here's the Hour class
public class Hour {
private int time;
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
}
Now, I'm not sure what JSF does behind the scenes to make this dynamic dataTable data iteration through the hours List possible, but I assume that if this is happening all in one thread, then it is okay. However, what if behind the scenes, the getHours is used in another thread that actually does the generating columns and see Hour in a bad state? This could be avoided if the getHours() method was
public List<Hour> getHours() {
final List<Hour> hours = new ArrayList<>();
for (int i = 0; i < 5; i++) {
hours.add(new Hour(i + ""));
}
return hours;
}
with the corresponding Hour class being
public class Hour {
private final int time;
public Hour(int time) {
this.time = time;
}
public int getTime() {
return time;
}
}
However, my question is that, if it wasn't changed to the latter design, can things go wrong when using basic dynamic JSF dataTable rendering due to visibility issues in Java when publishing this Hour instances?