You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Igor Vaynberg (JIRA)" <ji...@apache.org> on 2007/12/14 19:18:43 UTC

[jira] Resolved: (WICKET-1227) Provide easier access to items of RefreshingView

     [ https://issues.apache.org/jira/browse/WICKET-1227?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-1227.
-----------------------------------

       Resolution: Won't Fix
    Fix Version/s: 1.3.0-rc3

the whole point of the class hieararchy of refreshingview and down is that you dont manage the items yourself, the view manages the items for you. if you want to have access to items then use the low level repeatingview.

> Provide easier access to items of RefreshingView
> ------------------------------------------------
>
>                 Key: WICKET-1227
>                 URL: https://issues.apache.org/jira/browse/WICKET-1227
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>            Reporter: Peter Ertl
>            Assignee: Igor Vaynberg
>             Fix For: 1.3.0-rc3
>
>         Attachments: AccessItemsOfRefreshingView.patch
>
>
> When trying to directly access items of a RefreshingView (or subclasses of it) everything gets really complicated.
> For Example:
> When inserting a new, blank post into a guestbook the input focus should be set to the input field 'author'.
>   public void onClick(final AjaxRequestTarget target)
>   {
>     // add new, blank entry to the guestbook posts model
>     posts.add(new Post());
>     // 
>     // code that gets us the last item of the repeating view.
>     // however, the view first has to be rendered in order to contain the new item
>     // as it's only in the model but will not appear in the RefreshingView unless
>     // RefreshingView#onBeforeRender() is called
>     Item lastItem = ...???...
>     target.addComponent(/* container that contains the refreshing view */);
>     target.focusComponent(lastItem.get("author")); 
>   }
> Now what I did is attach a patch to provide methods for updating and getting the items of the RefreshingView.
> the above example would look like this:
> public void onClick(final AjaxRequestTarget target)
> {
>   posts.add(new Post());
>   guestbookView.refresh();
>   Item[] items = guestbookView.items();
>   Item lastItem = items[items.length() - 1];
>   target.addComponent(/* container that contains the refreshing view */);
>   target.focusComponent(lastItem.get("author")); // put focus on "author" component where user can enter his name
> }
> Basically it works like this:
> the refresh() method will invoke onBeforeRender() to populate the items of the view (based on the current model). That way you can access the items before the actual render occurs (using the iterator function MarkupContainer#getItems() ). Once the render occurs it would be just too late...
> In order to prevent unnecessary subsequent calls of onBeforeRender() a flag will remember if the view needs refreshing, so onBeforeRender() is only called once per render (unless you call refresh() for another time).
> items() is a convenience method that collects the current items using MarkupContainer#getItems() and returns a handy array of items and avoids cumbersome code.
> I also added firstItem() and lastItem() as I think these will be quite common use cases for accessing that array.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.