001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wicket.markup.repeater.data;
018:
019: import org.apache.wicket.markup.html.navigation.paging.IPageable;
020:
021: /**
022: * DataView is a basic implementation of AbstractDataView.
023: *
024: * Data views aim to make it very simple to populate your repeating view from a
025: * database by utilizing {@link IDataProvider} to act as an interface between
026: * the database and the dataview.
027: *
028: *
029: *
030: * <p>
031: * Example:
032: *
033: * <pre>
034: * <tbody>
035: * <tr wicket:id="rows">
036: * <td><span wicket:id="id">Test ID</span></td>
037: * ...
038: * </pre>
039: *
040: * <p>
041: * Though this example is about a HTML table, DataView is not at all limited to
042: * HTML tables. Any kind of list can be rendered using DataView.
043: * <p>
044: * And the related Java code:
045: *
046: * <pre>
047: * add(new DataView("rows", dataProvider)
048: * {
049: * public void populateItem(final Item item)
050: * {
051: * final UserDetails user = (UserDetails)item.getModelObject();
052: * item.add(new Label("id", user.getId()));
053: * }
054: * });
055: * </pre>
056: *
057: * @see IDataProvider
058: * @see IPageable
059: *
060: * @author Igor Vaynberg (ivaynberg)
061: *
062: */
063: public abstract class DataView extends DataViewBase {
064:
065: /**
066: * @param id
067: * component id
068: * @param dataProvider
069: * data provider
070: */
071: public DataView(String id, IDataProvider dataProvider) {
072: super (id, dataProvider);
073: }
074:
075: /**
076: * @param id
077: * component id
078: * @param dataProvider
079: * data provider
080: * @param itemsPerPage
081: * items per page
082: */
083: public DataView(String id, IDataProvider dataProvider,
084: int itemsPerPage) {
085: super (id, dataProvider);
086: setItemsPerPage(itemsPerPage);
087: }
088:
089: /**
090: * Sets the number of items to be displayed per page
091: *
092: * @param items
093: * number of items to display per page
094: */
095: public void setItemsPerPage(int items) {
096: internalSetRowsPerPage(items);
097: }
098:
099: /**
100: * @return number of items displayed per page
101: */
102: public int getItemsPerPage() {
103: return internalGetRowsPerPage();
104: }
105:
106: /**
107: * @return data provider
108: */
109: public IDataProvider getDataProvider() {
110: return internalGetDataProvider();
111: }
112:
113: }
|