Using table component,not binding
Hi all,
I've been searching info about using the table component
, adding,deleting,etc programatically, not binding to a Database how the JSC tutorial works.
The idea is simply:
- add and remove rows when the user fills a textbox and push a button to add the item.....
Anyone have an example or a link with examples?
thanks in advance!
[381 byte] By [
NewLitusa] at [2007-11-27 8:58:55]

# 1
Try using an object list data provider. Create the data provider and set the provider's list property to a list containing objects of a given type.
Be aware that you'll need to implement a workaround for a bug in the object list data provider. The following tutorial shows you how.
http://blogs.sun.com/winston/entry/objectlistdataprovider_workaround
You can then bind the table columns to the object's properties.
You can also add columns with buttons for editing and deleting rows. A button outside the table can also be used to add rows.
When you create the object list, add a few objects to it. (You can clear the list in the session bean's init method.) There are two reasons for this. First, if the list is empty, JSC has no way of knowing what kind of object the list is intended for. And second, when you do the binding, you'll see actual data in the table.
I know I've seen a tutorial or something about how to use the object list data provider, but I couldn't find it.
If I do find it, I'll post the link here.
# 2
>
> The idea is simply:
> - add and remove rows when the user fills a textbox
> and push a button to add the item.....
>
> Anyone have an example or a link with examples?
>
Two useful links to you:
1) http://developers.sun.com/jscreator/learning/bookshelf/index.jsp
In particular, download Chapters 8 and 9 and study them. Chapter 9 has exactly what you are asking for
2) The weblog of Wiston Prakash at http://blogs.sun.com/winston/, he shows you near-to-ultimate control on manipulating tables and their rows. Just look for the string "table" within that page.
Ragards,
Mohsen
# 5
What I do is create a list with, say, two Person objects then use ObjectListDataProvider's setList(List) method to associate the list with the data provider's list property.
I create the data provider in a session bean. In the bean's init method I call remove the dummy list items.
Before you can bind this data provider's list to any components you have to build the project, then close and reopen the project. Otherwise, JSC won't detect the presence of the data provider.
Here's an example from my program. Note that any package or import beginning with com.cfi.office refers to custom code.
This first class is the data provider. I added a convenience method clear the list but you don't have to do that.package com.cfi.office.dataproviders;
import com.cfi.office.schema.tables.Phone;
import com.sun.data.provider.impl.ObjectListDataProvider;
import java.util.ArrayList;
import java.util.List;
public class PhoneListDataProvider extends ObjectListDataProvider {
public PhoneListDataProvider() {
List phoneList = new ArrayList();
phoneList.add(new Phone("1112223333", "444");
phoneList.add(new Phone("5556667777", "888");
this.setList(phoneList);
}
public void clearList() {
this.getList().clear();
return;
}
}
This next code fragment is from a session bean.public void init() {
super.init();
try {
_init();
} catch (Exception e) {
log("BidSessionBean Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
abContactPhoneListDP.clearList();
}
private PhoneListDataProvider abContactPhoneListDP = new PhoneListDataProvider();
public PhoneListDataProvider getAbContactPhoneListDP() {
return this.abContactPhoneListDP;
}
public void setAbContactPhoneListDP(PhoneListDataProvider abContactPhoneListDP) {
this.abContactPhoneListDP = abContactPhoneListDP;
}
After you build the project, close it and reopen it, you should see the data provider in the binding dialog box.