tags:

views:

32

answers:

1

Hello everybody, i want to present one shopping cart in index i want to show 3 column and 5 row for each category Example

Books
||  Books A   ||   Books B     || Books C
||============||===============||=========
||  Books D   ||    Books E    ||  Books F
||============||===============||=========
||  Books G   ||     Books H   ||  Books I

Video
||   Video A  || Video B       ||  Video C
||============||===============||=========
||  Video D   || Video E       || Video F
||============||===============||=========
|| Video G    || Video H       || Video I

How can i do it like my example ?

+1  A: 

If you use JSF2.0 and Facelets, you could use <ui:repeat> and <h:dataTable> tags. Make your bean return items grouped in categories. In categories, keep list of items rows. Row is just an array (could be list too).

@ManagedBean
public class Cart {
  List<CategoryItems> getItemsGroupedInCategories() {
    //get items here
  }
}

public class CategoryItems {
  private String categoryName;
  private List<Item[]> itemsRows;
  //constructors, getters/setters
}

Then in JSF XHTML you put:

<ui:repeat value="#{cart.itemsGroupedInCategories}" var="categoryItems">
  <h:dataTable value="#{categoryItems.itemsRows}" var="row" >
    <f:facet name="header">
      <h:outputText value="#{categoryItems.categoryName}" />
    </f:facet> 
    <h:column>
      <h:outputText value="#{row[0]}" />
    </h:column>
    <h:column>
      <h:outputText value="#{row[1]}" />
    </h:column>
    <h:column>
      <h:outputText value="#{row[2]}" />
    </h:column>
  </h:dataTable>
</ui:repeat>
amorfis
I disagree using `h:dataTable` here. But I can't answer until the OP clarifies the environmental details. I just don't want to post about 4 different ways to achieve this the right way depending on the environment.
BalusC
Ok, but why do you disagree using `h:dataTable`?
amorfis
thank you two you , i using JSF 2.0 :D, ok i will try it :D
Kency