sys_debug
sys_debug

Reputation: 4003

Java JSF DataTable definition

I am trying to create a datatable using JSF primefaces. I know there is a tag called datatable but am really unclear on how to use it. As in I can't picture its relationship with the bean. My table should be ID, Status, Details. Any idea how to do this or where to go for it? oh forgot to add that the number of rows will depend on returned from resultset from database. Thanks,

Upvotes: 0

Views: 360

Answers (2)

sys_debug
sys_debug

Reputation: 4003

the answer I needed after Jigar helped me greatly is:

               <p:dataTable style="width:50px;" id="requestList" value="#
                {requestBean.requestsList}" var="requestClass">  
                <p:column>  
                    <f:facet name="header">  
                        <h:outputText value="ID" />  
                    </f:facet> 
                     <a href="review.xhtml?id=#{requestClass.requestID}">
                        <h:outputText value="#{requestClass.requestID}" />  
                     </a>

                </p:column>  

                <p:column>  
                    <f:facet name="header">  
                        <h:outputText value="Status" />  
                    </f:facet>  
                    <h:outputText value="#{requestClass.requestStatus}" />  
                </p:column>  

                  <p:column>  
                    <f:facet name="header">  
                        <h:outputText value="Details" />  
                    </f:facet>  
                      <h:outputText value="#{requestClass.requestTitle}" />  
                </p:column>
            </p:dataTable>  

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240966

You need to convert your result set into the List of entity (for example List<Book> ) and then set it as Bean 's property,

and use following code in XHTML

 <p:dataTable id="books" value="#{yourBean.books}" var="book">  

    <p:column>  
        <f:facet name="header">  
            <h:outputText value="Title" />  
        </f:facet>  
        <h:outputText value="#{book.title}" />  
    </p:column>  

    <p:column>  
        <f:facet name="header">  
            <h:outputText value="Author" />  
        </f:facet>  
        <h:outputText value="#{book.author}" />  
    </p:column>  

</p:dataTable>  

Book POJO

public class Book{
  private String author;
  private String title; 
  //accessors + constructors 
}

Managed Bean

@ManagedBean
public class YourBean{
  private List<Book> books;
  //accesors + constructors 
} 

See Also

Upvotes: 3

Related Questions