I am able to print the data from a JSF home page in form of table. But the issue is that it is able to print only one entry at a time.What if I enter more names i.e. name and password without using Database. Please find managed bean and format of table is taken by tutorial.
@SessionScoped
@ManagedBean(name = "pprBean")
public class Demos {
static String firstname ;
static String password;
private static final ArrayList<Demos> employees
= new ArrayList<Demos>(Arrays.asList(
new Demos()
));
public ArrayList<Demos> getEmployees() {
return employees;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view>
<h:body>
<h:form>
<h:panelGrid columns="4" cellpadding="5">
<h:outputLabel for="name" value="Name:" style="font-weight:bold"/>
<p:inputText id="name" value="#{pprBean.firstname}" />
<h:outputLabel for="pass" value="Pass:" style="font-weight:bold"/>
<p:inputText id="pass" value="#{pprBean.password}" />
<p:commandButton value="Submit"/>
</h:panelGrid>
<p:outputLabel value="Result"></p:outputLabel>
<h:dataTable value="#{pprBean.employees}" var="result" cellspacing="2"
styleClass="employeeTable"
headerClass="employeeTableHeader"
rowClasses="employeeTableOddRow,employeeTableEvenRow" border="3">
<h:column>
<f:facet name="header">Name</f:facet>
#{result.firstname}
</h:column>
<h:column>
<f:facet name="header">Password</f:facet>
#{result.password}
</h:column>
</h:dataTable>
</h:form>
</h:body>
</f:view>
</html>