Creating page object for dynamic content page types - pageobjects

I want to write page object for a page that has a dynamic section which toggles on button click. Since the view is not same, logically there are three sections, of which only one can be seen at a time.
<Div id=view1/> or
<Div id=view2/> or
<Div id=view3/>
MyPage < SitePrism::Page
[Other elements and sections]
[Dynamic section or element]
End
I thought of programming the page object in several ways.
1) Create 3 page objects for each view it can handle. This is not scalable because number of view might increase. Also number of such dynamic section may increase total number of different page objexts exponentially. That is:
MyPage1 with section pointing to view1. Like wise for view 2 and 3.
2) have all sections possible in the same object. This works fine but the page object does not look intuitive.
MyPage < SitePrism::Page
Section :view1, Section::View1, "#view1"
Section :view2, Section::View2, "#view2"
Section :view3, Section::View3, "#view3"
End
3) define method that takes care of creating the section at runtime. This way my page does not have the section at load time but once thr page is loaded I call appropriate method that loads the section in the page. ( this is not implemented but I think it might work, although it would require as many methods in page object as number of such dynamic sections)
Sample:
MyPage < SitePrism::Page
Def self.createView(type)
If type == view1
Section :view1, Section::View1, "#view1"
Elsif type == view2
(Like above for view 2)
Else
(Like above for view 3)
End
End
End
If you have come across similar problem, I would love to know if there is any other approach that can be taken, Or let me know if you foresee any problem with third approach.

Related

How to count element of one controller into another

i've a question to ask for my mvc project...
i have two controllers: Giurisprudenza e GiurisprudenzaNode, these controllers implement an index with the list of elements and a crud system to add/edit/remove elements. In the Girusiprudenza view page every element has a button that return you into the relative GiurisprudenzaNode page, with the list of elements contained into the primary element.
I would like to insert a label next to every element of the list in Giurisprudenza that say how many elements there are into that single primary element, but i don't know how to do that count... Anybody can help me?
for this you dont need two controllers or two different view .
For this you need to follow below steps.
Create a viewModel (Customize mix of both models)
add custom property in you this viewmodel for counts
create new view for this ViewModel class .
Let me know if you need code snippet for this.
View Model from MSDN

GWT SimplePager issues

I am using GWT's (2.5) SimplePager class in my application, to display pre-loaded data (I know the exact row count in advance).
The issue is with the last page. Given I have, for instance, 42 elements with an initial visible range of 10.
First page is 1-10, second 11-20, third 21-30, fourth, 31-40.
The issue is that fifth page is not 41-42 (which I want, because I want to be able to scroll back and forth and "land" exactly on the same data) but 33-42.
I have tried various tinkering with overriding SimplePager / AbstractPager methods, with no success.
For instance, if I override setPageStart, do the same as com.google.gwt.user.cellview.client.AbstractPager.setPageStart(int) but with the following commented out (I think it is the culprit code):
if (isRangeLimited && display.isRowCountExact()) {
index = Math.min(index, display.getRowCount() - pageSize);
}
The last page is fine (41-42), but this erases page size forever and when I go from last page to previous page, it becomes 40-41 (expected: 31-40). This is probably because the page size is not some constant provided to the pager instance, but is calculated with the Range object which was last used ("int pageSize = range.getLength();" in setPageStart method).
Any clue on modifying the paging behavior to my needs without breaking anything ?
Thanks !
I eventually got a working solution which is simple enough.
I provided a page size (which is the maximum number of elements that could be displayed, regardless of the total number of elements available to display) to my SimplePager object. Then I overrided getPage(), hasNextPage(), hasNextPages(int), hasPreviousPages(int), nextPage(), previousPage(), setPageStart(int) to use the provided page size instead of getLength() on the Range object.
To test this more easily (still done by hand...) I used GWT's Showcase project (and ran it in dev mode).
The downside is that I had to copy the code of the overriden methods (from AbstractPager - SimplePager does nothing except calling the superclass' methods) into my Pager class.

Preserve the scroll position of a Page

I have a page with many elements (forms and tables)
When I want add a row in a table I scroll the page to the table, I press a button to add a row, edit the info in a popup and press OK.
Then I insert the new row in the model and refresh() the model.
At this point the page auto scroll at the top, but I don't want this behavior!
I want that the page stay in the same Y position!
I see that sap.m.page has scrollTo function https://openui5.hana.ondemand.com/docs/api/symbols/sap.m.Page.html#scrollTo
but I don't know how take the position before the refresh()
The Page does unfortunately not have an API to get the current scroll position, but the idea is a good one we consider.
As a workaround you could access some private method of the Page - but only if you accept the risk that it breaks with a future version of UI5:
page.getScrollDelegate().getScrollTop()
To make it safer you should verify both methods exist before calling them and also check the returned value for plausibility. Then you are pretty safe that in the worst case it will again scroll to the top in some future UI5 version.
you have to fill the iTime parameter in scrollTo function - e.g. srollTo(100, 1) - then it works
using 0 for iTime does not work

Any way to find double current pages in turn.js?

My requirement is to display the current double pages in following format:-
2-3
4-5
and I only done with displaying singe page at a time however there is a double page view.
like
2 at 2-3
4 at 4-5
Any idea how do I fetch these current double pages in expected format?
I know I can do it by using adding logic, but would be better if I do it with internal logic of turnjs.
because It can be happen only single page comes sometimes like cover page or last page. I am sure there must be a way to find by turnjs only.
Any help will be appreciated...
Thanks in Advance.
I found its solution.. There is an array with the name view that holds the page's numbers to display. If there is a page 1 it holds the value
view[0] =1
View [1]=0
Similarly if its a last page lets say page 12 then the value in view will be
View [0]=0
View [1]=12
And if we are at 4-5 pages then
View [0]=4
View [1]=5
Got the solution :)
To be more specific here you can use this property.
view
Eg.
var view = $("#flipbook").turn("view").join(" - ");
alert("Current view: "+view);
It will return like this.
0 - 1
2 - 3
.......
Read here: http://www.turnjs.com/docs/Property:_view

Erratic UIPageControls

I'm using two UIPageControls in a view to reflect chapters and pages. So I have defined one UIPageControl named chapterCount and one named pageCount just to show where the user is. I handle the flipping of the pages with swipes rather than using the UIPageControls (so no methods defined for them).
I change their values as the user change pages with the following code:
chapterCount.numberOfPages = chapters;
chapterCount.currentPage = chapterNumber;
pageCount.numberOfPages = pages;
pageCount.currentPage = pageNumber;
[chapterCount updateCurrentPageDisplay];
[pageCount updateCurrentPageDisplay];
Where chapters, chapterNumber, pages and pageNumber all are integers.
The first time I flip through the pages it normally works fine, but when I go to a previous chapter or start a new chapter, the first (or last depending on direction) dot is not showed. Please see picture (upper half is missing a dot, lower one OK).
alt text http://img80.imageshack.us/img80/3339/pagecontrol.png
Its the same code updating the controls and sometime I get a dot, sometimes not. When I check the variables with NSLOG they are correct (eg the same for both pictures above).
I have checked Apple's documentation and tried their example but no luck.
Where should I start troubleshooting? I'm getting crazy!!
I finally found the problem :-)
An UIPageControl that is given a value 0 for number of pages will not show correctly the next time it is updated. I was reading chapter and page numbers from an array and in the beginning (let's say cover of the book) there are no pages and no chapters to show, so I happily set these to 0. Since I did not want to change the source data in my array I used MAX(pages , 1) for numberOfPages, so now it's working like clockwork.
Are you sure your chapterCount and pageCount views are not nil? You can have valid values all day, a message to nil does nothing and returns nil. Double check your view and controller wiring/unwiring when you change chapters.
EDIT:
confirm the size of the control is big enough to hold all your pages, and the view bounds is not clipped. For example, if you had 10 pages, and the "current" page was 10, but there were only 9 dots visible, it would appear as though nothing is highlighted because the white dot would be clipped from the visible area by being outside the viewable bounds. You can adjust the size dynamically using this:
- (CGSize)sizeForNumberOfPages:(NSInteger)pageCount