Re: Desktop app: how to tie Swing and JPA
Chuck Davis <cjgunzel <at> gmail.com>
2006-09-01 02:07:02 GMT
Have you looked at the tutorials?
On 8/31/06, Witold Szczerba <pljosh.mail <at> gmail.com> wrote:
> 2006/8/31, dwieringa <dnabble <at> oursmall.net>:
> > Question: What are some recommended resources for getting up to speed on
> > best practises of tieing a swing interface to JPA?
>
> Hi, that is what bites me for some time. I want to prototype some
> application that has UI in Swing/NB Platform and EJB3+JPA connected to
> desktop application using either JAX-WS or native jee5
> RMI/IIOP/whatever they call it...
>
> I am looking forward for some suggestion, however in a mean time I
> have created one very simple desktop application with bundled database
> HSQL and JPA from Hibernate EM.
> I have used JGoodies binding framework. I used SelectionInList and
> BeanAdapter classes (on my form there is a JTable with all visits of
> logged user, when you select one row of a table then its listener is
> loading selected visits' properties into beanAdapter.
>
> Then I have created JTextFields and JSpinners by dropping them on a
> form, then selected JSpinners and JTextFields one by one, and entered
> my own factory methods in "Properties/Code/Custom Creation Code" like
> this:
>
> model.jSpinnerFactory();
>
> This method creates new JSpinner, adds to it some listener (which
> notifies it when entity is selected from JTable) and returns this
> jSpinner.
>
> Then I went to "Properties/Model" and entered there code like this:
>
> model.spinnerNumberModelFactory("someProperty")
>
> This is the method that actually creates JSpinner model using JGoodies
> data binding (it binds this model to BeanAdapter.
> There is SelectionInList involved as well, but this is something you
> have to figure out by yourself (I couldn't understand this JGoodies
> binding for couple of days until I was ready to use it, so you have to
> go through their articles, presentations and tutorials by yourself.
>
> I know this is all a litle bit raw, but till now I have not found
> anything better. There is this JSR-295 that will address it to make it
> a standard way, there is also some JSR for preparing Swing for easier
> data binding, but until Java 7 we are all by our own in this area.
>
> Actually I really DO NOT UNDERSTAND this... Swing is so old already,
> and there is still no CLEAR and EASY way to bind a bunch of its basic
> components to properties of some object (like JPA entity, which looks
> from outside as a regular java class with properties) without writing
> hundreds lines of stupid, error prone code :/ But this JGoodies is a
> step in a good direction, so think about this.
>
> I would be very glad to hear from this great community: how are you
> dealing with binding swing forms with jpa/database to get simple
> functionality (like creating a form with swing widgets and binding
> them to database, so one could load any JPA bean, and its properties
> would be automatically loaded to widgets' models, and vice versa -
> someone is changing a jTextField, press 'save' button and it goes
> automatically into a database... I found frustrating the fact, that
> JGoodies binding works best if your model is a JavaBean with bound
> properties, but JPA does not have bound properties!... and I am not
> going to have 3 layers of data: JPA <--> JavaBeans <--> widgets'
> models)
>