Note that there are some explanatory texts on larger screens.

plurals
  1. POSync object with values in GUI using Metawidget
    primarykey
    data
    text
    <p>I'm using <a href="http://metawidget.sourceforge.net/" rel="nofollow">Metawidget</a> to automatically see/edit values in objects in the GUI. I'm able to bind the object's initial values, and see them in their respective GUI components. However, when I change the values in the GUI, these changes are not sync'ed back to the object. This is more or less documented <a href="http://blog.kennardconsulting.com/2008/02/beans-binding-in-metawidget.html" rel="nofollow">here</a> (deprecated) and <a href="http://metawidget.sourceforge.net/doc/reference/en/html/ch07.html" rel="nofollow">here</a>.</p> <p>Here is my business object:</p> <pre><code>public static class Person { private String mName; public String getName() { return this.mName; } public void setName( String name ) { this.mName = name; } @UiAction public void showPersonObject() { JOptionPane.showMessageDialog(frame, this.mName); } @UiAction public void bind() { metawidget.getWidgetProcessor( BeansBindingProcessor.class) .save( metawidget ); } } </code></pre> <p>Here is my main method, where metawidget is configured:</p> <pre><code>public static void main( String[] args ) { // Person Person person = new Person(); person.setName("A cool name"); // Metawidget metawidget = new SwingMetawidget(); metawidget.setInspector( new CompositeInspector( new CompositeInspectorConfig().setInspectors( new PropertyTypeInspector(), new MetawidgetAnnotationInspector(), new BeanValidationInspector()))); metawidget.addWidgetProcessor( new BeansBindingProcessor( new BeansBindingProcessorConfig().setUpdateStrategy( UpdateStrategy.READ_WRITE )) ); metawidget.setToInspect( person ); // Create Frame ... } </code></pre> <p>In the <a href="http://metawidget.sourceforge.net/doc/reference/en/html/ch07.html" rel="nofollow">documentation</a> it is said that:</p> <blockquote> <p>If set to READ or READ_WRITE (the default is READ_ONCE), the object being inspected must provide PropertyChangeSupport. If set to READ_WRITE, updates to the UI are automatically sync'ed back to the setToInspect, otherwise the client must manually call save:</p> <p>myMetawidget.getWidgetProcessor( BeansBindingProcessor.class ).save( myMetawidget )</p> </blockquote> <p>I've tried setting the <em>UpdateStrategy</em> to READ and/or READ_WRITE, and/or calling save() on <em>BeansBindingProcessor</em>. I've also tried to provide <em>PropertyChangeSupport</em> to the <em>Person</em> object (I think its refering to <a href="http://docs.oracle.com/javase/7/docs/api/java/beans/PropertyChangeSupport.html" rel="nofollow">this</a>), which is the same as adding the following code:</p> <pre><code>private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); public void addPropertyChangeListener(PropertyChangeListener listener) { this.pcs.addPropertyChangeListener(listener); } public void removePropertyChangeListener(PropertyChangeListener listener) { this.pcs.removePropertyChangeListener(listener); } public void setName( String name ) { String oldName = this.mName; this.mName = name; this.pcs.firePropertyChange("name", oldName, mName); } </code></pre> <p>However, the <em>Person</em> object always maintains the original values.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload