[
https://issues.apache.org/jira/browse/WICKET-1227?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12552066
]
Peter Ertl commented on WICKET-1227:
------------------------------------
Using newItem() is pretty smart :-) in that focus case but I still think this
is not solving the problem in general.
The 'setting focus' issue is just a very simple example. I want to provide a
general purpose way of applying javascript related stuff to parts of the data
view depending on any kind of complex logic, not just 'adding an item'. For
that you will virtually always need the markupId of components located inside
the RefreshingView's items.
Providing access to the items is not counteracting the philosophy of not
managing the items yourself but let RefreshingView do it. I see it more as an
extension. Giving you an array of Item[] will _not_ enable you to add, delete
or change order of the items. It just gives you access to the properties of
item and its children.
> 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.