• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7792
  • Last Modified:

How can I create dynamic datatable in backing bean in jsf (visual jsf)?

I have to create dataTable in jsf in netBeans 6.5.1 (visual jsf, appServer=glassfish, os=windows xp).
I receive data dynamically from web service....
I don't know how many column, nor number of rows I would have.
And I have to do that in prerender() method of that page, because when someone click link, I have to display that page.
Now, in my jsp, I have tag for dataTable (h:dataTable) with some properties (not column-tag there).
And in java file of that jsp (backing bean) in prerender method I can get name of column and style of column (I put code down)...
Data for properties of column are in my headers variable and in my rows variable are data for rows.
My problem is how can I add data (rows) to my table; map data to my table?
Hope you can help me...

----------------> TableGeneric.jsp:
... <h:dataTable binding="#{webs$TableGeneric.dataTable1}" headerClass="list-header" id="dataTable1"  rowClasses="list-row-even,list-row-odd" value="#{webs$TableGeneric.dataTable1Model}">
----------------> TableGeneric.java: ...
private HtmlDataTable dataTable1 = new HtmlDataTable(); 
public void prerender(){...
   List<HeaderFieldDefinition> header;
   Map<Integer, Map<String, RowField> > rows;
   UIColumn column;
   List<UIComponent> childrenList = dataTable1.getChildren();
   HtmlOutputText headerPrint;
        /*in tableData there are data and I have everything but I don't actually know write rows in data */
          header = tableData.getHeader();
          rows = tableData.getRows();
//in this for loop, I get what I need for name of column, style, etc and via getChildren() and add() //method I map that to a table; but I don't know do that with row 
          for(HeaderFieldDefinition hfd : header){
                column  = new UIColumn();
                headerPrint = new HtmlOutputText();
//I do something like this for rows, but it's not quite ok:
      int i = childrenList.size();
//this is not good: in tempList remember all data like Html...I think that is my problem; I need //something else, I think?!
      List<HtmlOutputText> tempList = new ArrayList<HtmlOutputText>();
      HtmlOutputText row;
      Iterator it = rows.entrySet().iterator();
      int p =0;
      while (it.hasNext()) {
             Map<String, RowField> innerMap;
             innerMap = (Map<String, RowField>) ((Map.Entry)it.next()).getValue();
             Iterator iter = innerMap.entrySet().iterator();
             RowField rowField;
             while (iter.hasNext()) {
                    Map.Entry pairs = (Map.Entry)iter.next();
                    rowField = (RowField) pairs.getValue();
                    row = new HtmlOutputText();
              for(int j = 0; j < i; j++){
//here I have tempList fill with data and I know there is p rows and i columns...and what now
//System.out.println("--------------> p = "+p + "; i = "+i + "; tempList.size()" + tempList.size());

Open in new window

  • 2
1 Solution
iceberg100Author Commented:
I don't know if I ask understandable question.....
I want to know if I have a list of HtmlOutputData, how can I put that in a row field; each element of the list in one place in row?
Or if you have better idea, please?
iceberg100Author Commented:
I did it....
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now