4 Replies Latest reply on Jan 23, 2008 4:06 PM by Neil McFarlane

    Displaying dataTable row numbers with uiComponent, what am I

    Neil McFarlane Novice


      The Seam reference guide has the following snippet (pg. 113 / 322)

      Alternatively, you can access the JSF component tree through the implicit uiComponent handle. The following
      example accesses getRowIndex()of the UIData component which backs the data table during iteration, it prints
      the current row number:
      <h:dataTable id="lineItemTable" var="lineItem" value="#{orderHome.lineItems}">
      Row: #{uiComponent['lineItemTable'].rowIndex}

      JSF UI components are available with their client identifier in this map.

      I've tried it in my code (shown below), but I only get a blank.
      <h:dataTable id="emailTable" value="#{person.emailAddresses}" var="email" rendered="#{not empty person.emailAddresses}">
       Row:<h:outputText value="#{uiComponent['emailTable'].rowIndex}"/>

      Is there something else I need to do to have it display?

        • 1. Re: Displaying dataTable row numbers with uiComponent, what
          mars1412 Apprentice

          does it work when you remove thr "row" column and just display smth. like emailAddresses.Id (or what ever)?

          maybe also post your person and emailAddresses source

          • 2. Re: Displaying dataTable row numbers with uiComponent, what
            Neil McFarlane Novice

            I've tried without the <h:output /> (so that it looked exactly as the demo) and had the same result.

            Nothing special about person, it's a fairly standard basic entity bean:

            package org.domain.myProject.entity;
            import java.util.ArrayList;
            import java.util.Collection;
            import javax.persistence.CascadeType;
            import javax.persistence.Entity;
            import javax.persistence.GeneratedValue;
            import javax.persistence.Id;
            import javax.persistence.OneToMany;
            import org.hibernate.validator.NotNull;
            import org.jboss.seam.annotations.Name;
            public class Person {
             @Id @GeneratedValue
             private Long id;
             private String name;
             @OneToMany(cascade = CascadeType.ALL, mappedBy="person")
             private Collection<EmailAddress> emailAddresses;
             public Long getId() {return id;}
             public void setId(Long id) {this.id = id;}
             public String getName() {return name;}
             public void setName(String name) {this.name = name;}
             public Collection<EmailAddress> getEmailAddresses() {
             return emailAddresses;
             public void setEmailAddresses(Collection<EmailAddress> emailAddresses) {
             this.emailAddresses = emailAddresses;
             public void addEmailAddress(EmailAddress email){
             if (emailAddresses == null) emailAddresses= new ArrayList<EmailAddress>();
             public void removeEmailAddress(EmailAddress emailAddress){
             if (emailAddresses != null){

            • 3. Re: Displaying dataTable row numbers with uiComponent, what
              Gene Campbell Newbie

              Check out this post

              Last post in that thread. Using binding as described worked for me.

              • 4. Re: Displaying dataTable row numbers with uiComponent, what
                Neil McFarlane Novice

                Hmm... I was hoping to avoid binding and creating additional components if possible. It's not a highly needed feature, and I think the solution on that thread outweighes the benefits.

                Still, nothing about the uiComponent? That looked like the nice and simple solution I was looking for.