Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:48:03+00:00 2026-06-10T16:48:03+00:00

I am trying to learn tapestry from tapestry tutorial , however part of it

  • 0

I am trying to learn tapestry from tapestry tutorial, however
part of it is outdated.

Using GridDataSource code for it is:

package com.packtpub.celebrities.util;
import com.packtpub.celebrities.data.IDataSource;
import com.packtpub.celebrities.model.Celebrity;
import java.util.List;
import org.apache.tapestry.beaneditor.PropertyModel;
import org.apache.tapestry.grid.GridDataSource;

public class CelebritySource implements GridDataSource {
  private IDataSource dataSource;
  private List<Celebrity> selection;
  private int indexFrom;

  public CelebritySource(IDataSource ds) {
    this.dataSource = ds;
  }

  public int getAvailableRows() {
    return dataSource.getAllCelebrities().size();
  }

  public void prepare(int indexFrom, int indexTo, PropertyModel propertyModel, boolean ascending) {
    String propertyName = propertyModel == null ? null : propertyModel.getPropertyName();

    System.out.println("Preparing selection.");
    System.out.println("Index from " + indexFrom + " to " + indexTo);        
    System.out.println("Property name is: " + propertyName);
    System.out.println("Sorting order ascending: " + ascending);

    this.selection = dataSource.getRange(indexFrom, indexTo);
    this.indexFrom = indexFrom;
  }

  public Object getRowValue(int i) {
    System.out.println("Getting value for row " + i);
    return selection.get(i - this.indexFrom);
  }

  public Class getRowType() {
    return Celebrity.class;
  }
}

method implementation prepare has changed now it looks like

public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints) {}

one of the few examples on google.com showing new method implementation is:

public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints) {
  for (SortConstraint constraint : sortConstraints) {
    final ColumnSort sort = constraint.getColumnSort();

    if (sort == ColumnSort.UNSORTED) continue;

    final PropertyConduit conduit = constraint.getPropertyModel().getConduit();

    final Comparator valueComparator = new Comparator<Comparable>() {
      public int compare(Comparable o1, Comparable o2) {
        // Simplify comparison, and handle case where both are nulls.
        if (o1 == o2) return 0;
        if (o2 == null) return 1;
        if (o1 == null) return -1;
        return o1.compareTo(o2);
      }
    };

    final Comparator rowComparator = new Comparator() {
      public int compare(Object row1, Object row2) {
        Comparable value1 = (Comparable) conduit.get(row1);
        Comparable value2 = (Comparable) conduit.get(row2);
        return valueComparator.compare(value1, value2);
      }
    };

    final Comparator reverseComparator = new Comparator() {
      public int compare(Object o1, Object o2) {
        int modifier = sort == ColumnSort.ASCENDING ? 1 : -1;
        return modifier * rowComparator.compare(o1, o2);
      }
    };

    // We can freely sort this list because its just a copy.
    Collections.sort(_list, reverseComparator);
  }
}

Is there any way to create functionality of the old code work using prepare method as it is now?

public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints) {}

Also would appreciate any other solution to this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:48:05+00:00Added an answer on June 10, 2026 at 4:48 pm

    It looks like the old prepare() method only let you sort on one criteria, whilst the new prepare() method lets you sort on many. (i.e. you can specify a secondary sort.)

    The propertyModel and an ascending / descending enum are now held in the SortConstraint object, but looking at the code, none of that is used! So to just get the example working, try this:

    public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints) {
      this.selection = dataSource.getRange(startIndex, endIndex);
      this.indexFrom = startIndex;
    }
    

    if you need the properyModel (for debugging) it should be accessible from:

    PropertyModel propertyModel = sortConstraints.get(0).getPropertyModel();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn Ruby, and in a tutorial, I came across this code on
I'm using m2eclipse and trying to learn some tapestry. I'm trying to update my
Trying to learn a bit about PDO and is going through this tutorial .
I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to
I was trying learn lex and yacc using the oreilly book. I tried following
Trying to learn HTML5 and downloaded a test project https://github.com/amiklosi/Comicr . There is a
Trying to learn ASP MVC coming from Linux/LAMP background (in other words I'm a
In trying to learn JavaScript closures, I've confused myself a bit. From what I've
Trying to learn GitHub at the moment and doing this Git essentials tutorial over
Im trying to learn how to use JSON from within codeigniter. I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.