Ignore:
Timestamp:
02/25/14 11:10:04 (10 years ago)
Author:
twagoo
Message:

added selector for number of results per page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/SearchResultsPanel.java

    r4553 r4554  
    2323import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel;
    2424import eu.clarin.cmdi.vlo.wicket.provider.SolrDocumentProvider;
     25import java.util.Arrays;
     26import java.util.List;
    2527import org.apache.solr.common.SolrDocument;
     28import org.apache.wicket.ajax.AjaxRequestTarget;
     29import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
    2630import org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator;
    2731import org.apache.wicket.markup.html.basic.Label;
     32import org.apache.wicket.markup.html.form.DropDownChoice;
     33import org.apache.wicket.markup.html.form.Form;
    2834import org.apache.wicket.markup.html.navigation.paging.IPageableItems;
    2935import org.apache.wicket.markup.html.panel.Panel;
     
    3339import org.apache.wicket.model.AbstractReadOnlyModel;
    3440import org.apache.wicket.model.IModel;
     41import org.apache.wicket.model.PropertyModel;
    3542import org.apache.wicket.spring.injection.annot.SpringBean;
    3643
     
    4148 */
    4249public class SearchResultsPanel extends Panel {
     50
     51    public static final List<Long> ITEMS_PER_PAGE_OPTIONS = Arrays.asList(5L, 10L, 25L, 50L, 100L);
    4352
    4453    @SpringBean
     
    6473        add(createResultPageIndicator("resultPageIndicator", resultsView));
    6574
     75        // form to select number of results per page
     76        add(createResultPageSizeForm("resultPageSizeForm", resultsView));
     77
    6678        //For Ajax updating of search results
    6779        setOutputMarkupId(true);
     
    8496    private Label createResultCount(String id) {
    8597        final IModel<String> resultCountModel = new AbstractReadOnlyModel<String>() {
    86            
     98
    8799            @Override
    88100            public String getObject() {
     
    106118    }
    107119
     120    private Form createResultPageSizeForm(String id, final IPageableItems resultsView) {
     121        final Form resultPageSizeForm = new Form(id);
     122
     123        final DropDownChoice<Long> pageSizeDropDown
     124                = new DropDownChoice<Long>("resultPageSize",
     125                        // bind to items per page property of pageable
     126                        new PropertyModel<Long>(resultsView, "itemsPerPage"),
     127                        ITEMS_PER_PAGE_OPTIONS);
     128        pageSizeDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
     129
     130            @Override
     131            protected void onUpdate(AjaxRequestTarget target) {
     132                target.add(SearchResultsPanel.this);
     133            }
     134        });
     135        resultPageSizeForm.add(pageSizeDropDown);
     136
     137        return resultPageSizeForm;
     138    }
     139
    108140    public static class SolrFieldLabel extends Label {
    109141
Note: See TracChangeset for help on using the changeset viewer.