GWT Editor with dynamic ListBox problem

819 views
Skip to first unread message

vinayak kulkarni

unread,
Jul 15, 2011, 1:48:23 AM7/15/11
to Google Web Toolkit
Hi,
Problem: How to use dynamic listbox with editor framework
I have the simple use case to display a List<String> in the listbox.
Then, the selected item in the listbox needs to be flushed from the
UI.
The values of the listbox are not static, they come from the DB during
runtime.

I wanted to implement it with editor mechanism.
But, the problem is, the input is - List<String> to show all the
values in the listbox
the output is just String - to be
flushed by the editor framework.

Previously, i used LeafValueEditor<String> with getValue() and
setValue().
getValue() --> flushes the selected value to the editor driver
setValue() --> unimplemented since it cannot accept the String
I implemented one more method setAllValues() to show the dropdown
values.

How, to handle this situation? when the getValue() and setValue() are
not of the same type?

I could think of ValueListBox with setAcceptablevalues(). But, how
does editor make a call to it?

Here is the flow:
Model
-- List<String> listValues
.. other objects

ModelView implements Editor<Model>
.. Model attributes with direct mapping
MyListBox listValues

MyListBox implements LeafValueEditor<String>
getValue()
setValue()

Presenter
-- Get model
-- editor driver.edit(model object)
set to view
=> The view is updated with model object

Let me know if there is any other way to make MyListBox widget to be
editor compliant and accepts List<String> but gives out String

Mauro Bertapelle

unread,
Jul 15, 2011, 4:52:21 AM7/15/11
to Google Web Toolkit
The subject of setValue is not a list of acceptable values but the
single item in the model data
Use a ValueListBox, and in presenter call setAcceptableValues to fill
list box before calling driver.edit

vinayak kulkarni

unread,
Jul 15, 2011, 5:16:18 AM7/15/11
to google-we...@googlegroups.com
I agree with you to call setAcceptableValue() before driver.edit

But, i have a different problem.. I need to edit the subEditor, which is ValueListBox

Presenter call driver.edit() on a widget ModelView.

ModelView has inner widget(sub editor) ValueListBox ex:


ModelView implements Editor<Model>
   .. Model attributes with direct mapping
      ValueListBox listValues;

Now, presenter doesnt know the inner widget(subEditor) ValueListBox. Presenter directly edits the Model.. ie. driver.edit(Model).. which inturn should call the subeditor to flush the values.

In this case, how to call the setAcceptableValues() from the presenter itself? 

It is that, we need to make the abstraction between View and Presenter and also use the editor mechanism from presenter to edit the view.

Let me know if there is any other way to do it.

Mauro Bertapelle

unread,
Jul 15, 2011, 5:51:20 AM7/15/11
to Google Web Toolkit
In View define a:
HasConstrainedValue getMyListValueWidget();

in Presenter:
view.getMyListValueWidget().setAcceptableValue(values);
driver.edit();

Tom Meech

unread,
Jul 15, 2011, 6:57:17 AM7/15/11
to google-we...@googlegroups.com
I've also been wondering about the best practice when using ListBox widgets and editors. My concern is when widgets in an editor have some dependencies. For example, country and city listboxes with the values of the city listbox dependant on the selected country.

The best way I can think of doing this at the moment, is to create a selectCountry method in the presenter (called when the country changes) which can then call a setCitySelection (with the new city values) in the view, the view can then setAcceptableValues in the widget.

This seem fine for a trivial example, but what if it gets more complicated? 

vinayak kulkarni

unread,
Jul 18, 2011, 5:50:47 AM7/18/11
to google-we...@googlegroups.com
Thanks..It worked out:-)
Reply all
Reply to author
Forward
0 new messages