Hi!

I have come up with a work-around not to loose the form components
when having to rebuild a ListView (after .removeAll).

I built a hashmaper for reusing the formComponents and it works ;)

However, I wonder if this could/should be incorporated within the
repeaters - what do you think? Furthermore, into which repeater should
it be incorporated? Any design ideas?

Here is the separate tool and its usage:

populateItem(...) {...
TextArea<String> descriptionField = new
TextArea<String>(DESCRIPTION_EDITOR, ...);
descriptionField = (TextArea<String>)
reuseManager.rememberOrReuse(task, DESCRIPTION_EDITOR,
descriptionField);
form.add(descriptionField);
}

And the reuseManager itself is simple as follows:

public class FormComponentReuseManager {
  private final Map<Object, Map<String, FormComponent<?>>> idMapRow =
new HashMap<Object, Map<String, FormComponent<?>>>();

  public FormComponent<?> rememberOrReuse(Object rowId, String
componentId, FormComponent<?> newComponent) {
    Map<String, FormComponent<?>> rowMap = createOrReuse(rowId);

    FormComponent<?> existingComponent = rowMap.get(componentId);

    if (existingComponent == null) {
      rowMap.put(componentId, newComponent);
      return newComponent;
    }

    // else
    return existingComponent;
  }

  private Map<String, FormComponent<?>> createOrReuse(Object rowId) {
    Map<String, FormComponent<?>> rowMap = idMapRow.get(rowId);
    if (rowMap == null) {
      rowMap = new HashMap<String, FormComponent<?>>();
      idMapRow.put(rowId, rowMap);
    }

    return rowMap;
  }
}




**
Martin



> Hi!
>
> What is the main difference between repeatingView and listView from
> this point of view?
>
> I can see ListView has many features I do not use such a s moving the
> rows up and down...
>
> **
> Martin
>
> 2008/6/11 Al Maw <[EMAIL PROTECTED]>:
>> This sort of stuff is definitely possible - people certainly have it working
>> elsewhere.
>>
>> If you use setReuseItems(true) you need to call removeAll() if you change
>> the backing model object.
>>
>> Timo is probably right that a RepeatingView may be easier to use in this
>> kind of situation.
>>
>> Alastair
>>
>> 2008/6/11 Martin Makundi <[EMAIL PROTECTED]>:
>>
>>> Hi!
>>>
>>> I have nested listviews which draw a complex tabular form having
>>> variable colspans and rowspans depending on the state of the form.
>>>
>>> I have an Add button to add elements into one of the inner listviews.
>>>
>>> Problem:
>>> 1. If I have "setReuseItems" true, the HTML table is not rendered
>>> properly (somehow the old table structure remains which should be
>>> restructured).
>>> 2. If I have "setReuseItems" false, the form components loose their
>>> state (unsubmitted entries) whenever I press the button.
>>>
>>> So. In my understanding, I need to both a) redraw the html table (at
>>> least update the colspan and rowspan attributes) and still b) preserve
>>> the form component state :) Is there an "out-of-the-box" solution for
>>> this?
>>>
>>> **
>>> Martin
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to