DataTable Conditional Row Messages

You are viewing an old version (v. 5) of this page.
The latest version is v. 11, last edited on Nov 01, 2012 (view differences | )
<< View previous version | view page history | view next version >>

DataTable supports 'supplementary' rows rendered on a condition; either at particular interval, before or after a column-value grouping, on 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.

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="#{row.id}" binding="#{backing.idOutput}" />
</ace:column>

Supplementary Row

The supplementary row will contain the h:messages component needed to show the messages resulting from the compnents 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}">
    <ace:column>
        <h:messages for="idOutput" style="font-size: 10pt; color:red; margin: 0.3em 0 0.5em 0;"/>
    </ace:column>
</ace:row>

Predicate Definition

The predicate is a function that is passed an object, 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 example of this fact, and references the iterative, data-bound outputText component of the row to use its clientId to find any attached messages.

@ManagedBean
@SessionScoped
public class ConditionalRowMessagesBean {
&nbsp;&nbsp;&nbsp; RowIdHasMessagesPredicate predicate = new RowIdHasMessagesPredicate();
&nbsp;&nbsp;&nbsp; UIOutput idOutput;


...

&nbsp;&nbsp;&nbsp; public UIOutput getIdOutput() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return idOutput;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; public void setIdOutput(UIOutput idOutput) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.idOutput = idOutput;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; public RowIdHasMessagesPredicate getPredicate() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return predicate;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; public void setPredicate(RowIdHasMessagesPredicate predicate) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.predicate = predicate;
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; public class RowIdHasMessagesPredicate implements Predicate {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public boolean evaluate(Object o) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return FacesContext.getCurrentInstance().
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getMessageList(idOutput.getClientId()).size() > 0;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
}
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.