call ListView.setReuseItems(true)

On Tue, Oct 27, 2009 at 1:24 PM, Martin Makundi <
[email protected]> wrote:

> > I'm using a CheckGroup together with a few Check in a repeater because
> the
> > number of boxes displayed is dynamic.
>
> If you have a repeater  the redraw event instantiates NEW checkboxes..
> so ofcourse you lose the staete.
>
> I have built a reusemanager that copies the old state. Usage sould be
> quite straight forward, ask if you need help.
>
> Here is a simple example of usage:
>
> add(reuseManager.rememberOrReuse(rowIndex, "custom_id", hoursField));
>
> :::
>
>
> public class FormComponentReuseManager implements Serializable {
>  private final Map<Object, Map<String, Component>> idMapRow = new
> HashMap<Object, Map<String, Component>>();
>
>
>  /**
>   * @param <S>
>   * @param <T>
>   * @param rowId
>   * @param componentId
>   * @param newComponent
>   * @return FormComponent
>   */
>  @SuppressWarnings("unchecked")
>  public <S, T extends FormComponent<S>> T rememberOrReuse(Object
> rowId, String componentId, T newComponent) {
>    return (T) rememberOrReuse(rowId, componentId, (Component)
> newComponent);
>  }
>
>  /**
>   * @param <T>
>   * @param rowId
>   * @param componentId
>   * @param newComponent
>   * @return FormComponent
>   */
>  public <T extends Component> T rememberOrReuse(Object rowId, String
> componentId, T newComponent) {
>    Map<String, Component> rowMap = createOrReuse(rowId);
>
>    @SuppressWarnings("unchecked")
>    T existingComponent = (T) rowMap.get(componentId);
>
>    if (newComponent instanceof FormComponent) {
>      // Never reuse the component itself, just reuse the
>      rowMap.put(componentId, newComponent);
>
>      if (existingComponent != null) {
>        MarkupUtils.fakeRawInput((FormComponent<?>)newComponent,
> (FormComponent<?>)existingComponent);
>        // Transfer also the error messages
>        for (FeedbackMessage feedbackMessage :
> TakpSession.get().getFeedbackMessages().messages(new
> ComponentFeedbackMessageFilter(existingComponent))) {
>          MarkupUtils.replaceReporter(feedbackMessage,
> (FormComponent<?>) newComponent);
>        }
>      }
>
>      return newComponent;
>    }
>
>    // else
>    if (existingComponent == null) {
>      rowMap.put(componentId, newComponent);
>      return newComponent;
>    }
>
>    // else
>    return existingComponent;
>  }
>
>  /**
>   * @param rowId
>   * @return Map<String, FormComponent>
>   */
>  private Map<String, Component> createOrReuse(Object rowId) {
>    Map<String, Component> rowMap = idMapRow.get(rowId);
>
>    if ((rowMap == null) && (rowId instanceof AbstractDTO) &&
> (((AbstractDTO) rowId).getId() != null)) {
>      rowId = ((AbstractDTO) rowId).getId();
>      rowMap = idMapRow.get(rowId);
>    }
>
>    if (rowMap == null) {
>      rowMap = new HashMap<String, Component>();
>      idMapRow.put(rowId, rowMap);
>    }
>
>    return rowMap;
>  }
>
>  /**
>   *
>   */
>  public void clear() {
>    idMapRow.clear();
>  }
>
>  /**
>   * @param <S>
>   * @param <T>
>   * @param key
>   * @param formComponent
>   * @param behaviors
>   * @return T
>   */
>  public <S, T extends FormComponent<S>> T
> rememberOrReuseAndProvideFeedback(
>      Object key, T formComponent, IBehavior... behaviors) {
>    formComponent.add(behaviors);
>    formComponent.setOutputMarkupId(true);
>    return rememberOrReuse(key, formComponent.getId(),
> FeedbackStyler.add(formComponent));
>   }
> }
>
>
> > This works fine and the data gets stored in the model correctly when
> > submitting.
> > However, if another form component fails in the validation, all
> checkboxes
> > are getting unchecked.
> > It seems the uuid increased after the error and does not match the
> submitted
> > data anymore.
> > In Check.onComponentTag(), the  group.hasRawInput() returns true and
> > contains for example  check60, check61  but the uuid variable is much
> higher
> > then, vor example 120, resulting in no checkbox being checked. It appears
> > that the Check's already got a new uuid and cannot be repopulated from
> the
> > submitted values as those values were different...?
> >
> > I'm using Wicket 1.3.5
> >
> > Thanks for your help
> >
> > Matt
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Pedro Henrique Oliveira dos Santos

Reply via email to