Wiki

Clone wiki

Oracle JSF Expert 1Z0-896 / dataTable and uirepeat

h:dataTable

Data source

  • A Java object
  • An array
  • An instance of java.util.List
  • An instance of java.sql.ResultSet
  • An instance of javax.servlet.jsp.jstl.sql.Result
  • An instance of javax.faces.model.DataModel

Attributes

  • bgcolor
  • border
  • captionClass
  • captionStyle
  • cellpadding
  • cellspacing
  • columnClasses
  • dir
  • first
  • footerClass
  • frame
  • headerClass
  • rowClasses
  • rows
  • rules
  • summary
  • var

Simple array example

@Named
@SessionScoped
public class TableData implements Serializable {
    private static final String[] names = new String[] {
        "paul", "tom", "dick", "harry" };

    public String[] getNames() {
        return names;
    }
}
<h:dataTable value="#{tableData.names}" var="name">
    <h:column>
        <f:facet name="header">
            Names
        </f:facet>
        #{name}
    </h:column>
</h:dataTable>

DataModel example

@ManagedBean
@ViewScoped
public class UserDataModelController {

    private DataModel<User> users;

    private User selectedUser;

    @PostConstruct
    public void init() {
        users = new ArrayDataModel<>(new User[] { new User("paul", "statham"), new User("tom", "jones"), new User("dick", "van dyke") });
    }

    public DataModel<User> getUsers() {
        return users;
    }

    public void setUsers(DataModel<User> users) {
        this.users = users;
    }

    public User getSelectedUser() {
        return selectedUser;
    }

    public void setSelectedUser(User selectedUser) {
        this.selectedUser = selectedUser;
    }

}
<h:dataTable id="static" var="u" value="#{userDataModelController.users}"
    frame="box">
    <f:facet name="caption">Table Caption</f:facet>
    <h:column>
        #{userDataModelController.users.rowIndex}
        <f:facet name="header">Index</f:facet>
    </h:column>
    <h:column>
        #{u.firstName}
        <f:facet name="header">User first name</f:facet>
    </h:column>
    <h:column>
        #{u.lastName}
        <f:facet name="header">User last name</f:facet>
    </h:column>
    <f:facet name="header">Static Users table</f:facet>
</h:dataTable>

ui:repeat

Attributes

  • offset
  • step
  • size
  • varStatus
    • Boolean properties even, odd, first and last
    • Integer properties index, begin, step and end

Simple array example

@Named
@SessionScoped
public class TableData implements Serializable {
    private static final String[] names = new String[] {
        "paul", "tom", "dick", "harry" };

    public String[] getNames() {
        return names;
    }
}
<table>
    <ui:repeat value="#{tableData.names}" varStatus="user">
        <tr>
            <td>#{tableData.names[user.index]}</td>
        </tr>
    </ui:repeat>
</table>

Updated