JSF - How to create a simple (JSF Data Table|ADF Table)

> Procedural Languages > Java > JavaServer Faces (JSF)

1 - About

How to create a data table with Eclipse OEPE ?

Advertising

3 - The Components

3.1 - The Bean

package tutorial;
 
public class myRow {
	private String id;
	private String description;
 
	// Constructor / Initialization
	public myRow(String id, String description) {
		this.id = id;
		this.description = description;
	}
 
	public String getId() {
		return id;
	}
 
	public void setId(String id) {
		this.id = id;
	}
 
	public String getDescription() {
		return description;
	}
 
	public void setDescription(String description) {
		this.description = description;
	}
 
}

3.2 - The Bean Controller

The managed bean with a variable of the type enumerable.

Note that Enumerable types include type

  • java.util.Collection,
  • java.util.Iterator,
  • java.util.Map,
  • and Java arrays.
package tutorial;
 
import java.util.ArrayList;
import java.util.List;
 
public class myRowController {
 
	private List<myRow> myRowsArrayList;
 
	private myRow[] myRowsArray = new myRow[] {
 
	new myRow("1", "RowsArray: First Description"),
			new myRow("2", "RowsArray: Second Description") };
 
	public myRowController() {
		myRowsArrayList = new ArrayList<myRow>();
		myRowsArrayList.add(new myRow("1", "ArrayList: First Description"));
		myRowsArrayList.add(new myRow("2", "ArrayList: Second Description"));
	}
 
	public myRow[] getMyRowsArray() {
		return myRowsArray;
	}
 
	public void setMyRowsArray(myRow[] myRowsArray) {
		this.myRowsArray = myRowsArray;
	}
 
	public List<myRow> getMyRowsArrayList() {
		return myRowsArrayList;
	}
 
	public void setMyRowsArrayList(List<myRow> myRowsArrayList) {
		this.myRowsArrayList = myRowsArrayList;
	}
 
}

3.3 - Jsf Page

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
	<jsp:directive.page contentType="text/html;charset=UTF-8" />
	<f:view>
		<af:document id="d1">
			<af:form id="f1">
				<af:table id="tableIteratorVariableArray"
					var="IteratorVariableArray"
					value="#{myRowControllerBeanName.myRowsArray}">
					<af:column id="c0" sortProperty="description" sortable="false"
						headerText="Description">
						<af:outputText id="description"
							value="#{IteratorVariableArray.description}"></af:outputText>
					</af:column>
					<af:column id="c1" sortProperty="id" sortable="false"
						headerText="Id">
						<af:outputText id="id" value="#{IteratorVariableArray.id}"></af:outputText>
					</af:column>
				</af:table>
			</af:form>
		</af:document>
	</f:view>
</jsp:root>

4 - Support

4.1 - Eclipse OEPE: The Data Palette does not show the variable

Just publish a page to the server and normally you will see appear the new variable.

5 - Documentation / Reference

Advertising