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

    Displaying dataTable row numbers with uiComponent, what am I

    oberiko

      Hello.

      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}">
      <h:column>
      Row: #{uiComponent['lineItemTable'].rowIndex}
      </h:column>
      ...
      </h:dataTable>

      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}">
       <h:column>
       Row:<h:outputText value="#{uiComponent['emailTable'].rowIndex}"/>
       </h:column>
      ...
      


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

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

          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
            oberiko

            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;
            
            @Entity
            @Name("person")
            public class Person {
            
             @Id @GeneratedValue
             private Long id;
            
             @NotNull
             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>();
             email.setPerson(this);
             emailAddresses.add(email);
             }
             public void removeEmailAddress(EmailAddress emailAddress){
             if (emailAddresses != null){
             emailAddresses.remove(emailAddress);
             }
             }
            }
            


            • 3. Re: Displaying dataTable row numbers with uiComponent, what
              ristretto

              Check out this post
              http://www.jboss.org/index.html?module=bb&op=viewtopic&t=105780

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

              • 4. Re: Displaying dataTable row numbers with uiComponent, what
                oberiko

                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.