[
https://issues.apache.org/jira/browse/WICKET-1227?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12552110
]
Igor Vaynberg commented on WICKET-1227:
---------------------------------------
fine, you can do that, but it doesnt need to be part of refreshing view, it can
be part of your own subclass
class myrefreshingview extends refreshingview {
private item[] items;
public void onbeforerender() {
super.onbeforerender();
items=new item[size()];
Iterator i=renderiterator(); int idx=0;
while (i.hasNext()) { items[idx++]=i.next(); }
}
public void detach() { items=null; super.detach(); }
public item[] getitems() { return items; }
}
works? yes you might have to create your own subclasses of refreshing view and
dataview, but thats life. having this as part of core bloats the api, adds an
extra storage slot to all refreshingview subclasses that will only be used
seldomly.
> 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.