dataTable + c:forEach + holder of each rowdata ...

UI Components for JSF
dante
Posts: 14
Joined: 22 Feb 2010, 00:59

22 Feb 2010, 02:30

I want dataTable with dynamic number of columns (result of search in ldap database ). I know that is not easy (for beginner like me) so I prepare some example code. When I inject holder of rowdata ("row") to attribute "items" of forEach then i get nothing (i think that table is rendered becouse I see micro rectangle , a few pixels). This is code from my xhtml page:

Code: Select all

<p:dataTable id="table" value="#{search.listOfLists}" var="row" >
                        <c:forEach items="#{row}" var="numberOfColumns">
                             <p:column>
                                  <f:facet name="header">
                                      <h:outputText value="#{numberOfColumns.attributeID}" />
                                  </f:facet>
                                  <h:outputText value="#{numberOfColumns.attributeValue}" />
                              </p:column>
                        </c:forEach>
</p:dataTable>
And some example code from search bean for testing:

Code: Select all

@ManagedBean(name = "search")
@SessionScoped
public class SearchBean implements Serializable {
    private List<List<TreeEntryInfo>> listOfLists;
    public SearchBean() {
        listOfLists = new ArrayList<List<TreeEntryInfo>>();
        List <TreeEntryInfo> example1 = new ArrayList<TreeEntryInfo>();
        List <TreeEntryInfo> example2 = new ArrayList<TreeEntryInfo>();
        List <TreeEntryInfo> example3 = new ArrayList<TreeEntryInfo>();
        example1.add(new TreeEntryInfo("id1", "value1"));
        example1.add(new TreeEntryInfo("id2", "value2"));
        example1.add(new TreeEntryInfo("id3", "value3"));
        example2.add(new TreeEntryInfo("id4", "value4"));
        example2.add(new TreeEntryInfo("id5", "value5"));
        example2.add(new TreeEntryInfo("id6", "value6"));
        example3.add(new TreeEntryInfo("id7", "value7"));
        example3.add(new TreeEntryInfo("id8", "value8"));
        example3.add(new TreeEntryInfo("id9", "value9"));
        listOfLists.add(example1);
        listOfLists.add(example2);
        listOfLists.add(example3);
}

    public List<List<TreeEntryInfo>> getListOfLists() {
        return listOfLists;
    }

    public void setListOfLists(List<List<TreeEntryInfo>> lol) {
        this.listOfLists = lol;
    }
TreeEntryInfo is a very simple class with two string variables: attributeID and attributeValue.
I imagine this situation as follows: i get list of lists from my querry on ldap. So attribute var in dataTable has list of objects (id - value) that holds one result from querry. I give that list to my old friend - c:forEach. He or She :p iterate on collection and create columns . But this is not work:( When I give collection from my bean (for example: <c:forEach items="#{search.someCollection}" var="numberOfColumns">) then forEach work's fine - create columns. Please help me;] I use 2.0.1-SNAPSHOT version + Mojarra 2.0.2 (FCS b10) + glassfish 3 //+ weak english ;p


PrimeFaces KICK ASS! I love it at first sight:D

dante
Posts: 14
Joined: 22 Feb 2010, 00:59

22 Feb 2010, 13:36

I check the attribute 'var' in dataTable and it really has a list of objects. Why c:forEach don't work on collection given by dataTable, but on collection "hard coded" in bean work perfect? :(

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

22 Feb 2010, 13:56

dante wrote:I check the attribute 'var' in dataTable and it really has a list of objects. Why c:forEach don't work on collection given by dataTable, but on collection "hard coded" in bean work perfect? :(
Hi,

Read this article please to understand why it doesn't work http://www.ilikespam.com/blog/c:foreach ... n-facelets
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

dante
Posts: 14
Joined: 22 Feb 2010, 00:59

22 Feb 2010, 15:52

In my case view (tree) is changing on a postback (one querry create 3 column table and for example another will create 6 column table). From this article follows that only ui:repeat can change view after that the tree is build. So I change the code to use <ui:repeat> and the result is the same like in <c:forEach>. This is the changed code:

Code: Select all

<p:dataTable id="table" value="#{search.listOfLists}" var="row" >
                        <ui:repeat value="#{row}" var="numberOfColumns">
                             <p:column>
                                  <f:facet name="header">
                                      <h:outputText value="#{numberOfColumns.attributeID}" />
                                  </f:facet>
                                  <h:outputText value="#{numberOfColumns.attributeValue}" />
                              </p:column>
                        </ui:repeat>
</p:dataTable>
I dont know what is going wrong:/
Anyway thanks for reply Oleg.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

22 Feb 2010, 17:28

Hello Dante,

As far as I know, p:dataTable is looking for p:column as direct children. ui:repeat will be ignored. I didn't try to create dynamic tables, but the one way to create such datatable described here http://balusc.blogspot.com/2006/06/usin ... cDatatable

You have to create dynamic datatable programmatically and bind to UI by "binding" attribute. For PrimeFaces I have suggested p:columns (see issue tracker). Hopefully we will get soon such possiblity. I will need it too.

Best regards.
Oleg.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

dante
Posts: 14
Joined: 22 Feb 2010, 00:59

22 Feb 2010, 17:49

DataTable iterate items in colection (attribute value) and return one (attribute var). In my example Iterate list of lists and return list:D I have some suspicous thought that attribute 'var' from p:dataTable wraps or do something weird with item(list in my case) given from collection in attribute 'value'. So c:forEach dont know how to handle this " wrap/weird;p collection" . Everything work when I pass to 'items' attribute from c:forEach the same collection, but from bean. Maybe someone know how work dataTable and attribute var in DETAILS;]

===========================================
THX Oleg, I try with programmatic dynamic table ;] It doesn't matter how, this driven me to despair, only one I want - working dynamic table ! ;]

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

22 Feb 2010, 21:22

I also want working dynamic table :-) Our datatables in the upcoming project are ALL dynamic. They are loaded by templates which describe them. I think, p:columns could help us in the feature :-) http://code.google.com/p/primefaces/iss ... %20Summary
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

dante
Posts: 14
Joined: 22 Feb 2010, 00:59

22 Feb 2010, 21:58

Sorry :( but again I have a problem. This happens when I change the HtmlDataTable to table from primefaces - DataTable (in code from balusc link - about programmatic dynamic datatable). Firebug show me this:
YAHOO.util.DataSource is not a constructor
(?)()
getTime()utilities.js (line 14)
getTime()utilities.js (line 14)
getTime()utilities.js (line 14)
[Break on this error] var formik_t_widget_datasource = new Y...AHOO.util.Dom.get('formik:t_table')); test.xhtml (line 68)

This is 68 line:
var formik_t_widget_datasource = new YAHOO.util.DataSource(YAHOO.util.Dom.get('formik:t_table'));

and this is a scrap of log:

Code: Select all

64<form id="formik" name="formik" method="post" action="/addressbook/faces/test.xhtml" enctype="application/x-www-form-urlencoded">
65<input type="hidden" name="formik" value="formik" />
66<span id="formik:pan"><script type="text/javascript">PrimeFaces.onContentReady('formik:t', function() {
67var formik_t_widget_columnDef = [{key:'rowIndex', hidden:true}];
68var formik_t_widget_datasource = new YAHOO.util.DataSource(YAHOO.util.Dom.get('formik:t_table'));
69formik_t_widget_datasource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
70formik_t_widget_datasource.responseSchema = {fields:[{key:'rowIndex'}]};
71formik_t_widget = new PrimeFaces.widget.DataTable('formik:t',formik_t_widget_columnDef,formik_t_widget_datasource, {dynamicData:false});
72});
73</script><div id="formik:t"><div id="formik:t_container"><table id="formik:t_table" style="display:none"><tbody><tr><td>0</td></tr><tr><td>1</td></tr><tr><td>2</td></tr><tr><td>3</td></tr><tr><td>4</td></tr></tbody></table></div></div></span><input type="submit" name="formik:j_idt22" value="export" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-5719076527293838398:-1521622650628718885" autocomplete="off" />
74</form><br /></div>
I must use primefaces dataTable becouse I want use data export to pdf,xls and csv.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

24 Feb 2010, 23:27

As Oleg mentioned we will add p:columns for this.

dante
Posts: 14
Joined: 22 Feb 2010, 00:59

25 Feb 2010, 00:27

SWEET!:D I don't want to be mean;], but I must ask a question - when this attribute will be added?
I discover a very weird behaviour. DataExport works on non existing dynamic dataTable. I add p:dataExporter to my page where I trying create dynamic table (problem with "YAHOO.util.DataSource is not a constructor" - code is above in post). On the page I see only button for export data from dynamic datatable. Unbelivible becouse dataExport works! The pdf has data from my non existing on page dynamic dataTable ! wow, what are You say about it ;]

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 54 guests