Re: Binding synchronization timing problems
Re: Binding synchronization timing problems
- Subject: Re: Binding synchronization timing problems
- From: Chuck Hill <email@hidden>
- Date: Thu, 29 Jun 2006 14:14:51 -0700
On Jun 29, 2006, at 1:59 PM, Miguel Arroz wrote:
I'm having some strange problem here, and I still could not
understand what's happening. It's somehow related to chapter 7,
Mysteries of Binding Synchronization on Practical WO book.
I have a table in my page, made with a WORepetition component. I
wanted to write a pager component, to "page" the table. So I
did! :) To link together the pager and the repetition, I used the
following schema:
Pager: PagerComponent {
partialList = reviewersPartialList;
originalList = reviewersList;
}
ReviewerRepetition: WORepetition {
list = reviewersPartialList;
item = currentReviewer;
index = currentIndex;
}
So, as you can see, the pager gets the full list from the top
level component (the "reviewersList") and has a "getter" method for
the partialList, which is the segment of the list that should be
shown.
WORepetition binds it's list to the partialList (a variable in
the top level component).
When the pager comes BEFORE the WORepetition, everything works as
it should. Pager does its magic, and the table displays accordingly.
Yes.
But we want the pager to show up after the WORepetition. So, I
moved it there. And the problem starts here.
Yes. Yes, it does. :-)
When I open the page for the first time, the table shows up empty.
The pager says we are on page one, and has links to all the other
pages, so the pager is working correctly. When I change the page,
the new page displays the table in the correct page, and everything
goes back to normal.
This is what I would expect based on what you have described.
So, my questions are:
1) Why does the table displays empty when the browser opens my
page for the first time? I was expecting something like this to
happen by reading Practical WO book, but I still did not fully
understand the mechanism.
Because when the table renders the first time, the PagerComponent has
not been created yet. So, it has not yet read reviewersList or set
reviewersPartialList. Your page is going to have to set up the
initial values
2) Why does the problem goes away after the first pager use? If I
clicked on page X, i was expecting to see page 1 (because it was
the last one that I should had seen). Then, clicking on page Y, it
would show X. But no. It shows X and Y, respectively.
Because at that point it has been created and is controlling the list
as you intend.
3) How do I solve this mess?
I can't think of how to solve this other than having the page set the
initial value of reviewersPartialList. In a case like this, I would
probably think "MVC" and separate the GUI in PagerComponent from the
logic of managing the list / sublists. The bindings would then
become something like:
Pager: PagerComponent {
pager = reviewersListPager;
}
ReviewerRepetition: WORepetition {
list = reviewersListPager.currentList;
item = currentReviewer;
index = currentIndex;
}
Add this to your application:
private ListPager reviewersListPager;
public ListPager reviewersListPager() { return reviewersListPager; }
And to your constructor (or other appropriate place
...
reviewersListPager = new ListPager(reviewersList);
reviewersListPager.selectFirstPage()
...
This has the advantage of separating the UI (view) from the model/
controller and will make your page work. :-) It has sort of a
disadvantage in that your pager is now two classes instead of one.
HTH
Chuck
--
Coming sometime... - an introduction to web applications using
WebObjects and Xcode http://www.global-village.net/wointro
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems. http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden