Dynamic datatable programmatically + weird error in firebug

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

23 Feb 2010, 16:01

On the BalusC page there is a tutorial how to create dynamic datatable programmatically and bind to UI by "binding" attribute. The code is for h:dataTable and it works fine;] When I change to use p:dataTable firebug on firefox 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>
This is the code from BalusC page:
The basic JSF code:

Code: Select all

<h:panelGroup binding="#{myBean.dynamicDataTableGroup}" />
The relevant Java code of the backing bean:

Code: Select all

package mypackage;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.el.ValueExpression;
import javax.faces.component.HtmlColumn;
import javax.faces.component.HtmlOutputText;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.context.FacesContext;

public class MyBean {

    // Init --------------------------------------------------------------------------------------

    private static List<List<String>> dynamicList; // Simulate fake DB.
    private static String[] dynamicHeaders; // Optional.
    private HtmlPanelGroup dynamicDataTableGroup; // Placeholder.

    // Actions -----------------------------------------------------------------------------------

    private void loadDynamicList() {

        // Set headers (optional).
        dynamicHeaders = new String[] {"ID", "Name", "Value"};

        // Set rows. This is a stub example, just do your dynamic thing.
        dynamicList = new ArrayList<List<String>>();
        dynamicList.add(Arrays.asList(new String[] { "ID1", "Name1", "Value1" }));
        dynamicList.add(Arrays.asList(new String[] { "ID2", "Name2", "Value2" }));
        dynamicList.add(Arrays.asList(new String[] { "ID3", "Name3", "Value3" }));
        dynamicList.add(Arrays.asList(new String[] { "ID4", "Name4", "Value4" }));
        dynamicList.add(Arrays.asList(new String[] { "ID5", "Name5", "Value5" }));
    }

    private void populateDynamicDataTable() {

        // Create <h:dataTable value="#{myBean.dynamicList}" var="dynamicItem">.
        HtmlDataTable dynamicDataTable = new HtmlDataTable();
        dynamicDataTable.setValueExpression("value",
            createValueExpression("#{myBean.dynamicList}", List.class));
        dynamicDataTable.setVar("dynamicItem");

        // Iterate over columns.
        for (int i = 0; i < dynamicList.get(0).size(); i++) {

            // Create <h:column>.
            HtmlColumn column = new HtmlColumn();
            dynamicDataTable.getChildren().add(column);

            // Create <h:outputText value="dynamicHeaders[i]"> for <f:facet name="header"> of column.
            HtmlOutputText header = new HtmlOutputText();
            header.setValue(dynamicHeaders[i]);
            column.setHeader(header);

            // Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the body of column.
            HtmlOutputText output = new HtmlOutputText();
            output.setValueExpression("value",
                createValueExpression("#{dynamicItem[" + i + "]}", String.class));
            column.getChildren().add(output);
        }

        // Add the datatable to <h:panelGroup binding="#{myBean.dynamicDataTableGroup}">.
        dynamicDataTableGroup = new HtmlPanelGroup();
        dynamicDataTableGroup.getChildren().add(dynamicDataTable);
    }

    // Getters -----------------------------------------------------------------------------------

    public HtmlPanelGroup getDynamicDataTableGroup() {
        // This will be called once in the first RESTORE VIEW phase.
        if (dynamicDataTableGroup == null) {
            loadDynamicList(); // Preload dynamic list.
            populateDynamicDataTable(); // Populate editable datatable.
        }

        return dynamicDataTableGroup;
    }

    public List<List<String>> getDynamicList() {
        return dynamicList;
    }

    // Setters -----------------------------------------------------------------------------------

    public void setDynamicDataTableGroup(HtmlPanelGroup dynamicDataTableGroup) {
        this.dynamicDataTableGroup = dynamicDataTableGroup;
    }

}
I want use primefaces data table ( export data to xls,pdf,csv ) so I change in this code two things: HtmlDataTable -> DataTable and HtmlColumn -> Colum.

Alucard
Posts: 1
Joined: 24 Feb 2010, 17:53

24 Feb 2010, 18:01

It looks like constructor of that object is different. In java code is everything ok?

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

27 Feb 2010, 11:05

Is that your code or is it from the blog you have mentioned?

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

02 Mar 2010, 16:18

This code is from BalusC blog( http://balusc.blogspot.com/2006/06/usin ... eDatatable ) . I change only two things (dataTable and cloumn). Code from blog is working with table from jsf, so I use it for testing with primefaces;] I lose to much time to do dynamic dataTable with primefaces:/ Now I am thinking about move to icefaces or another framework where I can do it. This is very sad decision becouse I LOVE PRIMEFACES! ;]
But maybe someone help me with this weird error - YAHOO.util.DataSource is not a constructor .
Thanks for all.

tofa
Posts: 46
Joined: 18 Feb 2010, 12:12

15 Mar 2010, 12:17

dante: did you solve the problem?
I have the same problem and found out some of it, see thread:
http://primefaces.prime.com.tr/forum/vi ... f=3&t=1652

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

15 Mar 2010, 16:23

dante can you post what p:resources render in <head>...</head> ? Resources doesn't seem to be loaded properly.

tofa
Posts: 46
Joined: 18 Feb 2010, 12:12

15 Mar 2010, 16:30

I get the same error but this example code works fine, so I guess the resources are corect?

Code: Select all

<p:dataTable var="car" value="#{tableBean.carsSmall} " >  
  <p:column>  
        <f:facet name="header">  
            Model  
        </f:facet>  
        <h:outputText value="#{car.model} " />  
    </p:column>  
  
    <p:column>  
        <f:facet name="header">  
            Year  
        </f:facet>  
        <h:outputText value="#{car.year} " />  
    </p:column>  
  
    <p:column>  
        <f:facet name="header">  
            Manufacturer  
        </f:facet>  
        <h:outputText value="#{car.manufacturer} " />  
    </p:column>  
  
    <p:column>  
        <f:facet name="header">  
            Color  
        </f:facet>  
        <h:outputText value="#{car.color} " />  
    </p:column>  
</p:dataTable>

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

15 Mar 2010, 16:41

My guess when creating a datatable dynamically, it can't register it's resources to no resources like js and css are rendered by p:resources assuming you are using JSF 1.2.

Current workaround would be manually place these resources using p:resource component.

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

15 Mar 2010, 21:53

Yes, I don't have resources for datatable. So I add :

Code: Select all

<p:resource>
<link rel="stylesheet" type="text/css" href="/evote-administration/primefaces_resource/2.0.0/yui/datatable/assets/skins/sam/datatable.css" />
<script type="text/javascript" src="/evote-administration/primefaces_resource/2.0.0/yui/datasource/datasource-min.js"></script>

<script type="text/javascript" src="/evote-administration/primefaces_resource/2.0.0/yui/datatable/datatable-min.js"></script>
<script type="text/javascript" src="/evote-administration/primefaces_resource/2.0.0/primefaces/datatable/datatable.js"></script>

</p:resource>
to head section and still have error - YAHOO.util.DataSource is not a constructor. My resources from head:

Code: Select all

<head>
<link rel="stylesheet" type="text/css" href="/evote-administration/primefaces_resource/2.0.0/yui/datatable/assets/skins/sam/datatable.css" />

<script type="text/javascript" src="/evote-administration/primefaces_resource/2.0.0/yui/datasource/datasource-min.js"></script>

<script type="text/javascript" src="/evote-administration/primefaces_resource/2.0.0/yui/datatable/datatable-min.js"></script>

<script type="text/javascript" src="/evote-administration/primefaces_resource/2.0.0/primefaces/datatable/datatable.js"></script>

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/yui/utilities/utilities.js"></script>

<link rel="stylesheet" type="text/css" href="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/primefaces/layout/layout.css" />

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/jquery/jquery.js"></script>

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/jquery/plugins/layout/jquery.layout.min.js"></script>

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/jquery/plugins/ui/jquery.ui.custom.js"></script>

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/primefaces/core/core.js"></script>

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/primefaces/layout/layout.js"></script>

<link rel="stylesheet" type="text/css" href="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/yui/menu/assets/skins/sam/menu.css" />

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/yui/container/container-min.js"></script>

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/yui/menu/menu-min.js"></script>

<link rel="stylesheet" type="text/css" href="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/yui/treeview/assets/skins/sam/treeview.css" />

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/yui/treeview/treeview-min.js"></script>

<script type="text/javascript" src="/AddressBook/primefaces_resource/2.0.1-SNAPSHOT/primefaces/treeview/treeview.js"></script>

<title>TEST</title></head> 

tofa
Posts: 46
Joined: 18 Feb 2010, 12:12

16 Mar 2010, 09:28

I see you added primefaces_resource/2.0.0/xyz.js
But the ones you have automatic in head is primefaces_resource/2.0.1-SNAPSHOT/xyz.js
So I guess you are using 2.0.1-SNAPSHOT? then you should add resources for that release.
I guess the ones you added can not be found, have a look in firebug and net tab, the ones that are red is not found.

Another ting I see is that the datatable js files use stuff in core.js and yui so they need to be last in the list.
I am not really sure what the best way to accomplish this but I added my <p:resource> in the <h:body>

-Tobias

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 52 guests