Imagine the implementation

if(there_is_a_transient_field)
{
   populate_all_data();
   sort_yourself_based_on_sort_constraint();
   paginate();
}
else
{
   pass_the_paging_and_sort_constraints_to_jpa();
}

Instead you already have a JPAGridDataSource and you can have your own
JPAInMemoryGridDataSource implementation :)

regards
Taha


On Tue, Jul 12, 2011 at 5:28 AM, Richard Yunhua Sang
<yunhua.s...@gmail.com>wrote:

> Hi Taha,
>
> I have no problem to write a new GridDataSource to do such thing; but as I
> said, it would be good to have this function in JPAGridDataSource.
>
> e.g.
>
> @Entity
> public class Student {
>
>    @Id
>    @GeneratedValue(strategy = GenerationType.IDENTITY)
>    private Long id;
>
>    private String firstName;
>
>    private String lastName;
>
>    public Long getId() {
>        return id;
>    }
>
>    public void setId(Long id) {
>        this.id = id;
>    }
>
>    public String getFirstName() {
>        return firstName;
>    }
>
>    public void setFirstName(String firstName) {
>        this.firstName = firstName;
>    }
>
>    public String getLastName() {
>        return lastName;
>    }
>
>    public void setLastName(String lastName) {
>        this.lastName = lastName;
>    }
>
>    @Transient
>    public String getName() {
>        return firstName + " " + lastName;
>    }
>
> }
>
> The users may want to show name only, and want to sort the list by name
> naturally.
>
> Thanks,
> Yunhua
>
>
>
> On Mon, Jul 11, 2011 at 7:43 PM, Taha Hafeez <tawus.tapes...@gmail.com
> >wrote:
>
> > Hi Richard,
> >
> > Internally JPAGridDataSource does not handle sorting itself, instead it
> > delegates it to JPA and transient values are unknown to JPA. If you want
> to
> > handle transient values, you will have to write you own implementation of
> > GridDataSource where in you can retrieve all the rows from the database
> and
> > based on the SortConstraints passed to prepare() method, sort the values
> > yourself.
> >
> > regards
> > Taha
> >
> > On Tue, Jul 12, 2011 at 4:58 AM, Richard Yunhua Sang
> > <yunhua.s...@gmail.com>wrote:
> >
> > > Thanks for your reply, but I do want to sort the result by transient
> > field
> > > in Grid. It would be appreciated that the JPAGridDataSource is able to
> > sort
> > > the result within JVM.
> > >
> > > On Mon, Jul 11, 2011 at 5:29 PM, Thiago H. de Paula Figueiredo <
> > > thiag...@gmail.com> wrote:
> > >
> > > > On Mon, 11 Jul 2011 18:06:17 -0300, Richard Yunhua Sang <
> > > > yunhua.s...@gmail.com> wrote:
> > > >
> > > >  Hi there,
> > > >>
> > > >
> > > > Hi!
> > > >
> > > >
> > > >  I am using a Grid with JpaGridDataSource; when I click sort icon on
> a
> > > >> transient field of an entity, I get following exception:
> > > >>
> > > >
> > > > I don't think any GridDataSource implementation backed by a database
> > > would
> > > > be able to handle transient properties, so you should set their
> > > > corresponding PropertyModel's as unsortable. To get the
> PropertyModel,
> > > > create a BeanModel for you entity class using the BeanModelSource
> > service
> > > > and use its get() method.
> > > >
> > > > --
> > > > Thiago H. de Paula Figueiredo
> > > > Independent Java, Apache Tapestry 5 and Hibernate consultant,
> > developer,
> > > > and instructor
> > > > Owner, Ars Machina Tecnologia da Informação Ltda.
> > > > http://www.arsmachina.com.br
> > > >
> > >
> >
>

Reply via email to