Can someone please tell me how to get the values of a particular index in my ArrayList to display? When I run the program the values do not display. I figured it out. Thanks! had to include the @PostConstruct
I am using Eclipse
// This is the JAVA file
package jsf2demo;
import java.util.*;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.inject.Named;
import java.io.Serializable;
import java.util.ArrayList;
@ManagedBean(name = "quiz")
@SessionScoped
public class QuizJSFBean implements Serializable {
private ArrayList<Integer> list = new ArrayList<Integer>();
public QuizJSFBean() {
}
public void setList() {
for (int i = 0; i < 10; i++) {
list.add((int) (Math.random() * 100));
}
}
public List<Integer> getList() {
return this.list;
}
}
// This is the separate HTML file
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Quiz</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="6">
<h:outputLabel style="text-align: right"
value="#{quiz.list[0]}" />
<h:outputLabel value="+" />
<h:outputLabel style="text-align: right"
value="#{quiz.list[1]}" />
<h:outputLabel value="=" />
</h:panelGrid>
</h:form>
</h:body>
</html>
// Not sure what addition detail I need to add