|
RIFE : Paged navigation builder
This page last changed on Aug 14, 2006 by koreth.
The PagedNavigation class provides utility methods to generate navigation for paged lists. The generation of the navigation depends on a collection of block and value IDs that should be defined in a template. Following is a table of all the IDs and their purpose: In addition to these template conventions, you must also provide one exit and one output that will be used to create the links that will perform the actual paging behaviour of the navigation. By default, the change_offset exit and the offset output will be used. It is up to you to create the datalink and flowlink and to correctly handle the offset value when it changes. A very basic paged navigation could for example be defined like this: <!--B 'NAV:FIRSTRANGE'--><a href="[!V 'EXIT:QUERY:change_offset'/]"><<</a><!--/B--> <!--B 'NAV:FIRSTRANGE:DISABLED'--><<<!--/B--> <!--B 'NAV:PREVIOUSRANGE'--><a href="[!V 'EXIT:QUERY:change_offset'/]"><</a><!--/B--> <!--B 'NAV:PREVIOUSRANGE:DISABLED'--><<!--/B--> <!--B 'NAV:ABSOLUTERANGE'--> <a href="[!V 'EXIT:QUERY:change_offset'/]"><!--V 'ABSOLUTERANGE_TEXT'/--></a> <!--/B--> <!--B 'NAV:ABSOLUTERANGE:DISABLED'--> <!--V 'ABSOLUTERANGE_TEXT'/--> <!--/B--> <!--B 'NAV:NEXTRANGE'--><a href="[!V 'EXIT:QUERY:change_offset'/]">></a><!--/B--> <!--B 'NAV:NEXTRANGE:DISABLED'-->><!--/B--> <!--B 'NAV:LASTRANGE'--><a href="[!V 'EXIT:QUERY:change_offset'/]">>></a><!--/B--> <!--B 'NAV:LASTRANGE:DISABLED'-->>><!--/B--> Pages: <!--V 'NAV:RANGECOUNT'/--> ( <!--V 'NAV:FIRSTRANGE'/--> <!--V 'NAV:PREVIOUSRANGE'/--> <!--V 'NAV:NEXTRANGE'/--> <!--V 'NAV:LASTRANGE'/--> | <!--V 'NAV:ABSOLUTERANGES'/--> ) This templating could result in the following output, where all the underlined parts are clickable and will trigger the change_offset exit and provide a new corresponding value for the offset output: Pages: 9 ( << < > >> | 1 2 3 4 5 6 7 8 9 ) The element that displays the list and calls the navigation generation method could for example be like this: @Elem(inputs={@Input(name=List.INPUT_OFFSET)})
public class List extends Element
{
public final static int LIMIT = 10;
public final static int SPAN = 5;
/* The name of the input that holds the list offset. */
public static final String INPUT_OFFSET = "offset";
/* Declares a flowlink back to this element that's used when the
user clicks on a navigation link. */
@FlowlinkExitField(destClass=List.class, datalinks={
@Datalink(srcOutput=INPUT_OFFSET, destInput=INPUT_OFFSET)})
public static final String EXIT_CHANGE_OFFSET = "change_offset";
public void processElement()
{
Template t = getHtmlTemplate("article.list");
DatabaseArticles manager = DatabaseArticlesFactory.getInstance();
int count = manager.countArticles();
if (0 == count) t.setBlock("content", "noarticles");
else
{
int offset = getInputInt(INPUT_OFFSET, 0);
PagedNavigation.generateNavigation(this, t, count, LIMIT, offset, SPAN);
Collection<Article> articles = manager.listArticles(LIMIT, offset);
for (Article article : articles)
{
t.setBean(article);
t.appendBlock("articles", "article");
}
}
print(t);
}
}
Take a look at the javadocs for more information. |
| Document generated by Confluence on Oct 19, 2010 14:56 |