Creator tip: How to create a table component dynamically

One of the questions often asked by the Sun Java Studio Creator customers is - How to create a table component dynamically?. This tip gives some hint on how to create a table component programmatically in a web application.

The preferred way to create a table component is by dragging and dropping it from the palette on to the designer and then bind it to a data provider. However, some advance users might want to create the table component programmatically based on some dynamic logic.



Great tip... I am a beginner in Java Creator2, and currently working on tables. So this really helped a lot. Is there a chance you could write an example on how to execute Oracle procedure (for example) and display the data on the form in a table? Thx...

Posted by Riz on March 30, 2006 at 10:59 PM PST #

I want to know if it is possible to have a table with say 2 1 row, then two rows, and then 3 rows, and back to 1 row in a single table????? This is indeed what I wish to accomplish and assistenace would be most appreciated

Posted by MATZORI on April 24, 2006 at 10:45 PM PDT #

Great article. I have more questions for you. 1) When you click one component in a table, the corresponding action will retrieve the value from the data provider. However, this causes the problem with the browser "BACK" button since at that time the data in provider are stale. How to retrieve the value actually displayed on the client's windows, rather than the value in data provider? 2) How to create a table without using data provider? I dont want to use gridpanel because I like the built-in features in the table component. Thanks in advance!

Posted by Field on May 23, 2006 at 02:17 PM PDT #

how to retrieve the information from the text file and store it in database?

Posted by P.Kavitha on July 26, 2006 at 02:49 PM PDT #

Thanks for this code, that was worth the reading. For those interrested, here is a sample code for adding both action and actionListener to a ImageHyperlink component:
                // Add the binding to the action method: public String imageHyperlink1_action()
                imageHyperlink.setAction(getApplication().createMethodBinding("#{Page1.imageHyperlink1_action}", null));
                // Add the binding to the actionListener method: public void chartsActionListener(ActionEvent ae)
                Class[] parameterList = { Class.forName("javax.faces.event.ActionEvent") };
                imageHyperlink.setActionListener(getApplication().createMethodBinding("#{Page1.chartsActionListener}", parameterList));
                // Add the ImageHyperlink to the GridPanel

Posted by Valère Déjardin on September 14, 2006 at 08:36 PM PDT #

Hi Valère, thanks for sharing the code.

Posted by Winston Prakash on September 14, 2006 at 11:58 PM PDT #

Very helpful article, but i was wondering is there a way to: Create a table WITHOUT using data provider? i´ve tried some thing but nothing seems to work, Thanks in advanced for any help!

Posted by MMH on October 06, 2006 at 12:53 AM PDT #

Hello, i have a dynamic create table component, and i want to do a single select line, as described on but unfortunately, it doesn't work. i checked everything, but couldn't see what's wrong. has anybody an idea? here's the code for creating the component: Table table = new Table(); table.setId("table1"); table.setTitle("Trefferliste"); table.setPaginateButton(false); table.setPaginationControls(false); // Create the Table Row group dynamically TableRowGroup rowGroup = new TableRowGroup(); rowGroup.setId("rowGroup1"); rowGroup.setRows(10); rowGroup.setSourceVar("currentRow"); rowGroup.setValueBinding("sourceData", FacesContext.getCurrentInstance().getApplication().createValueBinding("#{tochartawebctrl.objectListDataProvider1}")); // Add the table row group to the table as a child table.getChildren().add(rowGroup); // spalte für das image TableColumn rdbutton= new TableColumn(); rdbutton.setId("rb"); rdbutton.setHeaderText(""); RadioButton b = new RadioButton(); b.setSelectedValue(FacesContext.getCurrentInstance().getApplication().createValueBinding( "#{Client.selectedValue}")); b.setSelected(FacesContext.getCurrentInstance().getApplication().createValueBinding(("#{Client.selected}")); b.setName("rbsel"); rdbutton.getChildren().add(b); rdbutton.setOnClick("setTimeout('initAllRows()', 0)"); rdbutton.setSelectId("rbsel"); rowGroup.getChildren().add(rdbutton); TableColumn tcimg= new TableColumn(); tcimg.setId("image"); tcimg.setHeaderText("Ebene"); ImageComponent img = new ImageComponent(); img.setValueBinding("url", FacesContext.getCurrentInstance().getApplication().createValueBinding("#{currentRow.value['ebeneimage']}")); tcimg.getChildren().add(img); tcimg.setStyle("width:20px"); rowGroup.getChildren().add(tcimg); // spalte für die ordner_id TableColumn tcid= new TableColumn(); tcid.setId("id"); tcid.setHeaderText("id"); StaticText staticTextid = new StaticText(); staticTextid.setValueBinding("text", FacesContext.getCurrentInstance().getApplication().createValueBinding("#{currentRow.value['id']}")); // Add the static text to the table column1 tcid.getChildren().add(staticTextid); tcid.setRendered(false); // Add the first table Column to the table row group rowGroup.getChildren().add(tcid); rowGroup.setValueBinding("selected", FacesContext.getCurrentInstance().getApplication().createValueBinding("#{Client.selectedState}" ));

Posted by Sascha on December 06, 2006 at 02:10 AM PST #

hello, after two days studying what's differnt from my code to your code, i think it was the name property of the radio button which was missing. i am using internet explorer 6.0 now i didn't create the table dynamically. instead i use a table only with one radio button column. the other columns are added at runtime. sorry, for the code posting above. greetings sascha

Posted by Sascha on December 07, 2006 at 05:24 PM PST #

Hello, Thank you for this great article. But I have a question related to dynamic tables. I am doing an application with dynamic tables, but these tables must also be editable. But it seems that the data provider never gets updated with the information given by the user in the page. Is there any way to recover this data for integration in the database? Thank you for any comment on this.

Posted by Erik on December 18, 2006 at 04:43 PM PST #

Good Article.. But, Suppose I am creating these componenets dynamically then how to creat dynamic valuebinding for these components and how to access those values...

Posted by Prashant on January 17, 2007 at 06:32 PM PST #

Could you elaborate on your comment: "More over if the page is resubmitted, table and its sub components are reconstructed by faces application during restore view phase, so they should not be recreated again." Also, the way you've implemented the getGridPanel1 function, the table is recreated each time it is fetched. Could this safely be avoided i.e. in the context of the above quote?

Posted by Jeff on April 23, 2007 at 04:47 AM PDT #


Posted by guest on May 16, 2007 at 03:55 PM PDT #

Thanks for Good article. I created a table with Pagination controls. but first,previous,next and last are not working. how to solve it? Thanks in Advance

Posted by Abdullah on June 06, 2007 at 08:46 PM PDT #

This article is good, but I need help with the other side of the coin (i.e. I have a table and I want to dynamically fill its data provider with data that is NOT from a database).

I am collecting data for medical research, and need to manipulate/filter the data (using Java) before displaying it. I would like to keep this logic in the "presentation" layer, not the "database".

I am guessing that I need to use the data providers in the palette, but I can't find a description of how data providers should be used outside of attaching to a database.

Posted by Paul Gustitus on August 09, 2007 at 02:24 AM PDT #

Sorry, I forgot to mention:
I am using NetBeans 5.5.1 and Mysql 5.5.17.

Posted by Paul Gustitus on August 09, 2007 at 03:35 AM PDT #

Hello there..I'm real green JSF programmer. recently I have build a textArea for sql statements and a button(webuijsf:button) . Plus I have a table component which I wish to populate dynamically. However It's kin hard when especially the query involves more than more table. I cound't find a way to dynamically populate table component based on dynamic sql given by user.

Posted by kiddies on September 16, 2007 at 06:25 PM PDT #

Question: This example not worked in netbeans 6.0. How to create a table component dynamically in netbeans 6.0?

Posted by ttvvaa on October 10, 2007 at 05:58 PM PDT #


Posted by guest on December 17, 2007 at 06:27 PM PST #

i need help in jsf dynamic table

Posted by arul on July 22, 2009 at 05:23 PM PDT #

Hai I have developed dynamic table in jsf but i neeed textfield(column) into table and also need when
i doubleclick in textfield open popup page and that same time i want get rowkey and column name

in JSF+Netbeans6.0

Anybody is knows pls reply..
Iam waiting

Posted by arul radhakrishnan on July 22, 2009 at 05:27 PM PDT #

Dynamic table component having textfield ,Below link what i pass paramater


Posted by arul on July 22, 2009 at 09:52 PM PDT #

Dynamic table component having textfield ,Below link what i pass paramater


I need autocomplete expression

Posted by guest on July 22, 2009 at 09:53 PM PDT #

I am Using Sun Java Studio Creator 2 with Oracle Database.When Executing findFirst method I am getting error ("Statement not executed : getMetaData()")Example Code :
String cmd = "select \* from USERTB";

RowKey rowkey = usertbDataProvider.findFirst(
new String[] {"userid","password"},
new Object[] {"gayanitest","gayani"}

This code is perfectly running with Infomix database. But with Oracle 10g it is giving error.

Posted by Gayani Champika on June 02, 2010 at 05:07 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

« July 2016