DataTable Conditional Row Messages

compared with
Current by Feras Nasser
on Nov 01, 2012 19:41.

These lines were removed. This word was removed.
These lines were added. This word was added.

View page history

There are 1 changes. View first change.

 DataTable supports 'supplementary' rows rendered on a condition; either at particular interval, before or after a column-value grouping, or based on the result of an application defined conditon. This tutorial demonstrates the last technique, defining a condition that renders the supplementary row following a row whose h:outputText component has an attached FacesMessage.
 We will cover the definition of the 'normal' row, 'supplementary' row and the predicate that determines row rendering based on FacesMessage presence.
 The attachement of the FacesMessage to the component is merely to demonstrate the technique, and will not be covered in detail.
 h3. Normal Row
 The normal row will contain the columns (in this sample, 1 column) & components nessescary to render our row objects. Note the binding. This is used later to retrieve the clientId during predicate evaluation, to check for associated FacesMessages.
 <ace:column headerText="ID">
  <h:outputText id="idOutput" value="#{}" binding="#{backing.idOutput}" />
 h3. Supplementary Row
 The supplementary row will contain the h:messages component needed to show the messages resulting from the components of our standard row. The for property of the message component should be the client id of the normal row component that may have attached messages. One h:message component is required per component. If h:messages doesn't have 'for' defined, it prints the messages of all components in this page.
 <ace:row condition="predicate" predicate="#{backing.predicate}">
  <h:messages for="idOutput" style="font-size: 10pt; color:red; margin: 0.3em 0 0.5em 0;"/>
 h3. Predicate Definition
 The predicate is an object with a single method, with a single object argument, in this case an integer row index, and determines if the row satisfies the conditon. The predicate is also evaluted following iteration to the row index in question, so the request context variables are in sync with the correct row object. The predicate in this example takes advantage of this fact, and references the iterative, data-bound outputText component of the row to use its correctly indexed clientId to find any attached messages.
 public class ConditionalRowMessagesBean {
  RowIdHasMessagesPredicate predicate = new RowIdHasMessagesPredicate();
  UIOutput idOutput;
  public UIOutput getIdOutput() {
  return idOutput;
  public void setIdOutput(UIOutput idOutput) {
  this.idOutput = idOutput;
  public RowIdHasMessagesPredicate getPredicate() {
  return predicate;
  public void setPredicate(RowIdHasMessagesPredicate predicate) {
  this.predicate = predicate;
  public class RowIdHasMessagesPredicate implements Predicate {
  public boolean evaluate(Object o) {
  return FacesContext.getCurrentInstance(). // idOutput.getClientId() has diff results due to iteration
  getMessageList(idOutput.getClientId()).size() > 0;
 WIth these components, a whole range of row-level summary or description behaviours are possible, we hope this tutorial has given you some ideas of your own\!

© Copyright 2018 ICEsoft Technologies Canada Corp.