Netbeans Bean Binding - BindingGroup

View: New views
3 Messages — Rating Filter:   Alert me  

Netbeans Bean Binding - BindingGroup

by jasonwpalmer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Has anyone experienced problems with auto-generated beans binding wizard in Netbeans 6.5 (SWING) ? I have done a lot of Web Applications and am learning SWING. I might even learn quicker if I could learn how to code this manually, but many tutorials are written using the Wizards that Netbeans offers and when I have problems it is hard to pinpoint problems in auto-generated code!

When I drop a table on the page in the Visual Designer and try to setup the binding by right-clicking and selecting bind-->elements. I use a List that is populated in Constructor of JFrame with JPA that holds a List of Entity Beans. I know that the List is populated with Entities and Persistence.xml is all in order and functioning correctly.

Everytime the GUI is displayed it shows an empty table with default values defined in TableModel. Also when the Wizard completes in Visual Designer at Design Time - the table appears unchanged even though the Binding Wizard seems to have completed successfully.

I understand that I can extend AbstractTableModel and provide a concrete implementation and just bind the table appropriately. This seems to be alot of work and I would like to use JSR 295 BeansBinding instead.

Does anyone have a similiar problem that they have overcome?

Jason Palmer

Re: Netbeans Bean Binding - BindingGroup

by Jiri Vagner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!
So you want to use jtable binding to fill jtable content withou wizards.
Did I understand it correctly?

Small example:

 - add Car class to your project

public class Car {
    private String manufacturer;
    private String model;

    public String getManufacturer() {
        return manufacturer;
    }
    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
}


 - add bean property to your form

public class YourFrame extends javax.swing.JFrame {
    private List<Car> _cars = new ArrayList<Car>();

    public void setCarList(List<Car> cars) {
        _cars = cars;
    }
    public List<Car> getCarList() {
        if (_cars.isEmpty()) {
            Car car =new Car();
            car.setManufacturer("Lancia");
            car.setModel("Lybra");
            _cars.add(car);

            car = new Car();
            car.setManufacturer("Lancia");
            car.setModel("Thesis");
            _cars.add(car);
        }
        return _cars;
    }
.....

- select jTable and invoke bind dialog  Bind -> elements
- as Binding source set Form
- as Binding expression tree select node "carList java.util.List" or
just type  "${carList}"
- select fields to display
- run the form

Hope it helps.
Jirka Vagner


jasonwpalmer wrote:

> Has anyone experienced problems with auto-generated beans binding wizard in
> Netbeans 6.5 (SWING) ? I have done a lot of Web Applications and am learning
> SWING. I might even learn quicker if I could learn how to code this
> manually, but many tutorials are written using the Wizards that Netbeans
> offers and when I have problems it is hard to pinpoint problems in
> auto-generated code!
>
> When I drop a table on the page in the Visual Designer and try to setup the
> binding by right-clicking and selecting bind-->elements. I use a List that
> is populated in Constructor of JFrame with JPA that holds a List of Entity
> Beans. I know that the List is populated with Entities and Persistence.xml
> is all in order and functioning correctly.
>
> Everytime the GUI is displayed it shows an empty table with default values
> defined in TableModel. Also when the Wizard completes in Visual Designer at
> Design Time - the table appears unchanged even though the Binding Wizard
> seems to have completed successfully.
>
> I understand that I can extend AbstractTableModel and provide a concrete
> implementation and just bind the table appropriately. This seems to be alot
> of work and I would like to use JSR 295 BeansBinding instead.
>
> Does anyone have a similiar problem that they have overcome?
>
> Jason Palmer
>  


Re: Netbeans Bean Binding - BindingGroup

by jasonwpalmer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks For Your Time Jiri.

This is really driving me crazy here, and I have no doubt the problem is simple, but it does illustrate an ease of use issue with the Beans Binding support in Netbeans. And don't get me wrong, I LOVE Netbeans and appreciate every developer that has contributed, nevertheless I'm having problems figuring this out.

I have a private method defined in the JFrame that contains the main class for this project. The method follows:

private void prepareCategoryList(){
categoryList = ListGenerator.getCategories();
}

And then in constructor before initComponents.

        prepareCategoryList();
        initComponents();

And when I do exactly what you described right-click table that I have been previously using and bind it to the categoryList , java.util.List<Category>, it works fine. The table displays the data from the Database. So I know that the Category List is populated.

However, when a drag and drop a new table fro  the palette and drop it onto the Frame with the other table and bind it, it throws an Exception at startup.

init:
deps-jar:
compile-single:
run-single:
Calling getCategories!
[TopLink Config]: 2008.12.10 10:21:45.343--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The alias name for the entity class [class auto_html_alizer_v1p1.entity.PurchaseOrder] is being defaulted to: PurchaseOrder.
[TopLink Config]: 2008.12.10 10:21:45.436--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The alias name for the entity class [class auto_html_alizer_v1p1.entity.OrderItem] is being defaulted to: OrderItem.
[TopLink Config]: 2008.12.10 10:21:45.483--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The alias name for the entity class [class auto_html_alizer_v1p1.entity.Product] is being defaulted to: Product.
[TopLink Config]: 2008.12.10 10:21:45.499--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The alias name for the entity class [class auto_html_alizer_v1p1.entity.Login] is being defaulted to: Login.
[TopLink Config]: 2008.12.10 10:21:45.499--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The alias name for the entity class [class auto_html_alizer_v1p1.entity.Category] is being defaulted to: Category.
[TopLink Config]: 2008.12.10 10:21:45.499--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The alias name for the entity class [class auto_html_alizer_v1p1.entity.DexriptionBottom] is being defaulted to: DexriptionBottom.
[TopLink Config]: 2008.12.10 10:21:45.514--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The alias name for the entity class [class auto_html_alizer_v1p1.entity.DexriptionTop] is being defaulted to: DexriptionTop.
[TopLink Config]: 2008.12.10 10:21:45.514--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The target entity (reference) class for the many to one mapping element [private auto_html_alizer_v1p1.entity.PurchaseOrder auto_html_alizer_v1p1.entity.OrderItem.purchaseOrder] is being defaulted to: class auto_html_alizer_v1p1.entity.PurchaseOrder.
[TopLink Config]: 2008.12.10 10:21:45.592--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The target entity (reference) class for the one to many mapping element [private java.util.Collection auto_html_alizer_v1p1.entity.PurchaseOrder.orderItemCollection] is being defaulted to: class auto_html_alizer_v1p1.entity.OrderItem.
[TopLink Config]: 2008.12.10 10:21:45.623--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The target entity (reference) class for the one to one mapping element [private auto_html_alizer_v1p1.entity.Product auto_html_alizer_v1p1.entity.DexriptionBottom.product] is being defaulted to: class auto_html_alizer_v1p1.entity.Product.
[TopLink Config]: 2008.12.10 10:21:45.623--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The target entity (reference) class for the one to many mapping element [private java.util.Collection auto_html_alizer_v1p1.entity.Category.productCollection] is being defaulted to: class auto_html_alizer_v1p1.entity.Product.
[TopLink Config]: 2008.12.10 10:21:45.623--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The target entity (reference) class for the many to one mapping element [private auto_html_alizer_v1p1.entity.Category auto_html_alizer_v1p1.entity.Product.categoryId] is being defaulted to: class auto_html_alizer_v1p1.entity.Category.
[TopLink Config]: 2008.12.10 10:21:45.623--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The target entity (reference) class for the one to one mapping element [private auto_html_alizer_v1p1.entity.DexriptionTop auto_html_alizer_v1p1.entity.Product.dexriptionTop] is being defaulted to: class auto_html_alizer_v1p1.entity.DexriptionTop.
[TopLink Config]: 2008.12.10 10:21:45.623--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The target entity (reference) class for the one to one mapping element [private auto_html_alizer_v1p1.entity.Product auto_html_alizer_v1p1.entity.DexriptionTop.product] is being defaulted to: class auto_html_alizer_v1p1.entity.Product.
[TopLink Config]: 2008.12.10 10:21:45.623--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--The target entity (reference) class for the one to one mapping element [private auto_html_alizer_v1p1.entity.DexriptionBottom auto_html_alizer_v1p1.entity.Product.dexriptionBottom] is being defaulted to: class auto_html_alizer_v1p1.entity.DexriptionBottom.
[TopLink Info]: 2008.12.10 10:21:46.294--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))
[TopLink Fine]: 2008.12.10 10:21:46.669--Thread(Thread[AWT-EventQueue-0,6,main])--Detected Vendor platform: oracle.toplink.essentials.platform.database.MySQL4Platform
[TopLink Config]: 2008.12.10 10:21:46.684--ServerSession(11608737)--Connection(11446032)--Thread(Thread[AWT-EventQueue-0,6,main])--connecting(DatabaseLogin(
        platform=>MySQL4Platform
        user name=> "jasonwpalmer"
        datasource URL=> "jdbc:mysql://localhost:3306/auto_info_db"
))
[TopLink Config]: 2008.12.10 10:21:46.715--ServerSession(11608737)--Connection(9703298)--Thread(Thread[AWT-EventQueue-0,6,main])--Connected: jdbc:mysql://localhost:3306/auto_info_db
        User: jasonwpalmer@localhost
        Database: MySQL  Version: 5.0.45-community-nt
        Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
[TopLink Config]: 2008.12.10 10:21:46.715--ServerSession(11608737)--Connection(8801859)--Thread(Thread[AWT-EventQueue-0,6,main])--connecting(DatabaseLogin(
        platform=>MySQL4Platform
        user name=> "jasonwpalmer"
        datasource URL=> "jdbc:mysql://localhost:3306/auto_info_db"
))
[TopLink Config]: 2008.12.10 10:21:46.731--ServerSession(11608737)--Connection(6923467)--Thread(Thread[AWT-EventQueue-0,6,main])--Connected: jdbc:mysql://localhost:3306/auto_info_db
        User: jasonwpalmer@localhost
        Database: MySQL  Version: 5.0.45-community-nt
        Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
[TopLink Config]: 2008.12.10 10:21:46.731--ServerSession(11608737)--Connection(29494967)--Thread(Thread[AWT-EventQueue-0,6,main])--connecting(DatabaseLogin(
        platform=>MySQL4Platform
        user name=> "jasonwpalmer"
        datasource URL=> "jdbc:mysql://localhost:3306/auto_info_db"
))
[TopLink Config]: 2008.12.10 10:21:46.747--ServerSession(11608737)--Connection(23342038)--Thread(Thread[AWT-EventQueue-0,6,main])--Connected: jdbc:mysql://localhost:3306/auto_info_db
        User: jasonwpalmer@localhost
        Database: MySQL  Version: 5.0.45-community-nt
        Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
[TopLink Config]: 2008.12.10 10:21:46.747--ServerSession(11608737)--Connection(24769387)--Thread(Thread[AWT-EventQueue-0,6,main])--connecting(DatabaseLogin(
        platform=>MySQL4Platform
        user name=> "jasonwpalmer"
        datasource URL=> "jdbc:mysql://localhost:3306/auto_info_db"
))
[TopLink Config]: 2008.12.10 10:21:46.778--ServerSession(11608737)--Connection(28291271)--Thread(Thread[AWT-EventQueue-0,6,main])--Connected: jdbc:mysql://localhost:3306/auto_info_db
        User: jasonwpalmer@localhost
        Database: MySQL  Version: 5.0.45-community-nt
        Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
[TopLink Config]: 2008.12.10 10:21:46.778--ServerSession(11608737)--Connection(25106497)--Thread(Thread[AWT-EventQueue-0,6,main])--connecting(DatabaseLogin(
        platform=>MySQL4Platform
        user name=> "jasonwpalmer"
        datasource URL=> "jdbc:mysql://localhost:3306/auto_info_db"
))
[TopLink Config]: 2008.12.10 10:21:46.793--ServerSession(11608737)--Connection(9493)--Thread(Thread[AWT-EventQueue-0,6,main])--Connected: jdbc:mysql://localhost:3306/auto_info_db
        User: jasonwpalmer@localhost
        Database: MySQL  Version: 5.0.45-community-nt
        Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
[TopLink Config]: 2008.12.10 10:21:46.793--ServerSession(11608737)--Connection(25346354)--Thread(Thread[AWT-EventQueue-0,6,main])--connecting(DatabaseLogin(
        platform=>MySQL4Platform
        user name=> "jasonwpalmer"
        datasource URL=> "jdbc:mysql://localhost:3306/auto_info_db"
))
[TopLink Config]: 2008.12.10 10:21:46.825--ServerSession(11608737)--Connection(26548428)--Thread(Thread[AWT-EventQueue-0,6,main])--Connected: jdbc:mysql://localhost:3306/auto_info_db
        User: jasonwpalmer@localhost
        Database: MySQL  Version: 5.0.45-community-nt
        Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
[TopLink Config]: 2008.12.10 10:21:46.825--ServerSession(11608737)--Connection(26147562)--Thread(Thread[AWT-EventQueue-0,6,main])--connecting(DatabaseLogin(
        platform=>MySQL4Platform
        user name=> "jasonwpalmer"
        datasource URL=> "jdbc:mysql://localhost:3306/auto_info_db"
))
[TopLink Config]: 2008.12.10 10:21:46.840--ServerSession(11608737)--Connection(4512144)--Thread(Thread[AWT-EventQueue-0,6,main])--Connected: jdbc:mysql://localhost:3306/auto_info_db
        User: jasonwpalmer@localhost
        Database: MySQL  Version: 5.0.45-community-nt
        Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.7 ( Revision: ${svn.Revision} )
[TopLink Info]: 2008.12.10 10:21:47.059--ServerSession(11608737)--Thread(Thread[AWT-EventQueue-0,6,main])--file:/C:/Users/Jason/Documents/NetBeansProjects/Auto_HTML_Alizer_v1P1/dist/Auto_HTML_Alizer_v1P1.jar-Auto_HTML_Alizer_v1P1PU login successful
Starting Transaction!
[TopLink Fine]: 2008.12.10 10:21:47.121--ServerSession(11608737)--Connection(6923467)--Thread(Thread[AWT-EventQueue-0,6,main])--SELECT category_id, category_parent_id, category_description, category_title, category_image_url FROM tbl_categories
Categories Returned: true
Calling getCategories!
Starting Transaction!
[TopLink Fine]: 2008.12.10 10:21:47.168--ServerSession(11608737)--Connection(9703298)--Thread(Thread[AWT-EventQueue-0,6,main])--SELECT category_id, category_parent_id, category_description, category_title, category_image_url FROM tbl_categories
Categories Returned: true
[TopLink Config]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Connection(9703298)--Thread(Thread[Finalizer,8,system])--disconnect
[TopLink Info]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Thread(Thread[Finalizer,8,system])--file:/C:/Users/Jason/Documents/NetBeansProjects/Auto_HTML_Alizer_v1P1/dist/Auto_HTML_Alizer_v1P1.jar-Auto_HTML_Alizer_v1P1PU logout successful
[TopLink Config]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Connection(6923467)--Thread(Thread[Finalizer,8,system])--disconnect
[TopLink Config]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Connection(11446032)--Thread(Thread[Finalizer,8,system])--disconnect
[TopLink Config]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Connection(23342038)--Thread(Thread[Finalizer,8,system])--disconnect
[TopLink Config]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Connection(28291271)--Thread(Thread[Finalizer,8,system])--disconnect
[TopLink Config]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Connection(9493)--Thread(Thread[Finalizer,8,system])--disconnect
[TopLink Config]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Connection(26548428)--Thread(Thread[Finalizer,8,system])--disconnect
[TopLink Config]: 2008.12.10 10:21:47.308--ServerSession(11608737)--Connection(4512144)--Thread(Thread[Finalizer,8,system])--disconnect
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.JTable.prepareRenderer(JTable.java:5729)
        at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2075)
        at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1977)
        at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1773)
        at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
        at javax.swing.JComponent.paintComponent(JC
        at javax.swing.JComponent.paintComponent(JComponent.java:763)
        at javax.swing.JComponent.paint(JComponent.java:1027)
        at javax.swing.JComponent.paintChildren(JComponent.java:864)
        at javax.swing.JComponent.paint(JComponent.java:1036)
        at javax.swing.JViewport.paint(JViewport.java:747)
        at javax.swing.JComponent.paintChildren(JComponent.java:864)
        at javax.swing.JComponent.paint(JComponent.java:1036)
        at javax.swing.JComponent.paintChildren(JComponent.java:864)
        at javax.swing.JComponent.paint(JComponent.java:1036)
        at javax.swing.JComponent.paintChildren(JComponent.java:864)
        at javax.swing.JComponent.paint(JComponent.java:1036)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
        at javax.swing.JComponent.paintChildren(JComponent.java:864)
        at javax.swing.JComponent.paintToOffscreen(JComponent.java:5129)
        at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1472)
        at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1403)
        at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
        at javax.swing.JComponent.paint(JComponent.java:1013)
        at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
        at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
        at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
        at java.awt.Container.paint(Container.java:1762)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 7 seconds)

Why does the binding not work after following the Wizard to "hook it up" to the same List<Category> that the other table is "hooked up to"?

I obviously need to debug the source code and see where the tables have different properties, which will take a while.

Again, thanks for your time.

Jason Palmer

Jiri Vagner wrote:
Hi!
So you want to use jtable binding to fill jtable content withou wizards.
Did I understand it correctly?

Small example:

 - add Car class to your project

public class Car {
    private String manufacturer;
    private String model;

    public String getManufacturer() {
        return manufacturer;
    }
    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
}


 - add bean property to your form

public class YourFrame extends javax.swing.JFrame {
    private List<Car> _cars = new ArrayList<Car>();

    public void setCarList(List<Car> cars) {
        _cars = cars;
    }
    public List<Car> getCarList() {
        if (_cars.isEmpty()) {
            Car car =new Car();
            car.setManufacturer("Lancia");
            car.setModel("Lybra");
            _cars.add(car);

            car = new Car();
            car.setManufacturer("Lancia");
            car.setModel("Thesis");
            _cars.add(car);
        }
        return _cars;
    }
.....

- select jTable and invoke bind dialog  Bind -> elements
- as Binding source set Form
- as Binding expression tree select node "carList java.util.List" or
just type  "${carList}"
- select fields to display
- run the form

Hope it helps.
Jirka Vagner


jasonwpalmer wrote:
> Has anyone experienced problems with auto-generated beans binding wizard in
> Netbeans 6.5 (SWING) ? I have done a lot of Web Applications and am learning
> SWING. I might even learn quicker if I could learn how to code this
> manually, but many tutorials are written using the Wizards that Netbeans
> offers and when I have problems it is hard to pinpoint problems in
> auto-generated code!
>
> When I drop a table on the page in the Visual Designer and try to setup the
> binding by right-clicking and selecting bind-->elements. I use a List that
> is populated in Constructor of JFrame with JPA that holds a List of Entity
> Beans. I know that the List is populated with Entities and Persistence.xml
> is all in order and functioning correctly.
>
> Everytime the GUI is displayed it shows an empty table with default values
> defined in TableModel. Also when the Wizard completes in Visual Designer at
> Design Time - the table appears unchanged even though the Binding Wizard
> seems to have completed successfully.
>
> I understand that I can extend AbstractTableModel and provide a concrete
> implementation and just bind the table appropriately. This seems to be alot
> of work and I would like to use JSR 295 BeansBinding instead.
>
> Does anyone have a similiar problem that they have overcome?
>
> Jason Palmer
>