isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Haywood <...@haywood-associates.co.uk>
Subject Re: Apply pagination to collection (parented list)
Date Sun, 19 Mar 2017 15:58:53 GMT
Have raised https://issues.apache.org/jira/browse/ISIS-1598 to capture
these ideas.

On Fri, 10 Feb 2017 at 11:09 Arjun Gica Manipes <manipes.ag@sprobe.com>
wrote:

> Hi Dan,
>
> Thank you for quick response.
>
> We are mostly using Restful Objects.
> We were able to do this type of pagination on Action, by modifying the
> "ObjectActionArgHelper.java" to populate the pagination details.
>
> On method:  public List<ObjectAdapter> parseAndValidateArguments(final
> JsonRepresentation arguments) {...}
>
> // Handle page parameters
> if (paramSpec.getCorrespondingClass() == Pageable.class
>                 && argRepr != null
>                 /*&& argRepr.mapHas("value")
>                 && !argRepr.isNull("value")*/) {
>         /*final JsonRepresentation token =
> argRepr.getRepresentation("value");
>
>         final String tokenAsString = token.asString();*/
>
>         final PageRequest pageRequest;
>
>         if (argRepr.getString("sort") != null) {
>                 final String[] split = argRepr.getString("sort").split(":
> ");
>                 final Sort.Direction dir =
> Sort.Direction.fromStringOrNull(split[1]);
>                 pageRequest = new
> PageRequest(Integer.parseInt(argRepr.getString("pageNumber")),
>
> Integer.parseInt(argRepr.getString("pageSize")),
>                                 new Sort(dir, split[0]));
>         } else {
>                 pageRequest = new
> PageRequest(Integer.parseInt(argRepr.getString("pageNumber")),
>
> Integer.parseInt(argRepr.getString("pageSize")));
>         }
>
>
>         if (pageRequest != null) {
>                 // Encode pageable. This shall be deserialized later on.
>                 final ObjectAdapter adapter =
> getPersistenceSession().adapterFor(pageRequest);
>                 final EncodableFacet encodableFacet =
> paramSpec.getFacet(EncodableFacet.class);
>                 argRepr = JsonRepresentation.newMap();
>                 argRepr.mapPut("value",
> encodableFacet.toEncodedString(adapter));
>         } else {
>                 // No file for given token; throw error
>                 final String reason = "There is something wrong with your
> page parameters.";
>                 argRepr.mapPut("invalidReason", reason);
>                 throw new IllegalArgumentException(reason);
>         }
> }
>
>
> What we are thinking for the implementation:
>
> METHOD 1: Modify the existing metamodels.
>
> 1. On "ObjectCollectionReprRenderer.java" [1], we are thinking that we can
> insert Pageable arguments to this line
> 2. On " ObjectAssociation.java" [2], we might end up changing this line as
> well to accept Pageable parameter.
>
>
> METHOD 2: Create new metamodels which extends the existing metamodels.
>
> As mention, we are able to do this on Actions. And our intent to do this
> as well on Collections.
>
> We might as well asks for your suggestion on how to do this Dan or if
> there are any better implementation for this one.
>
>
> [1]
> https://github.com/apache/isis/blob/master/core/viewer-restfulobjects-rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/domainobjects/ObjectCollectionReprRenderer.java#L84
> [2]
> https://github.com/apache/isis/blob/master/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/feature/ObjectAssociation.java#L67
>
> Thanks and best regards,
> Arjun Gica Manipes
>
> -----Original Message-----
> From: Dan Haywood [mailto:dan@haywood-associates.co.uk]
> Sent: Friday, February 10, 2017 2:33 PM
> To: users@isis.apache.org
> Subject: Re: Apply pagination to collection (parented list)
>
> Fair enough.  But then how would you expect the framework's viewer to be
> able to also do this (instantiate and populate the Pageable).
>
> Let me step back a bit.
>
> When the framework iterates over your domain object classes, it looks for
> methods that meet certain naming conventions and from this it builds up its
> metamodel.  These methods are then invoked by the framework when the domain
> object is rendered/interacted with through the generic Wicket viewer.
>
> For example, if there's a method called placeOrder(Product, int) and a
> supporting method called validate0PlaceOrder(Product), it's the framework
> that figures out which Product to pass as an argument.
>
> It's not possible for the framework to be able to "magically" support your
> proposed getXxx(Pageable) because to so would require it to have knowledge
> of how to instantiate and populate the Pageable argument.
>
> If you have a proposal as to how it might, do explain / raise a ticket.
>
> Thx
> Dan
>
> On Fri, 10 Feb 2017 at 06:24 Arjun Gica Manipes <manipes.ag@sprobe.com>
> wrote:
>
> > Hi Dan,
> >
> > In our implementation the viewer instantiates and populates the
> > Pageable object.
> >
> > -----Original Message-----
> > From: Dan Haywood [mailto:dan@haywood-associates.co.uk]
> > Sent: Thursday, February 09, 2017 6:54 PM
> > To: users@isis.apache.org
> > Subject: Re: Apply pagination to collection (parented list)
> >
> > Ok, but I still don't understand I'm afraid... what would instantiate
> > and populate the Pageable object?
> >
> > On Thu, 9 Feb 2017, 09:38 Arjun Gica Manipes, <manipes.ag@sprobe.com>
> > wrote:
> >
> > > Hi Dan,
> > >
> > > Thank you for your response.
> > >
> > > We plan it to use on ViewModel only. There's no problem on DataNucleus.
> > > We want to add an extra parameter (Pageable) to getProperty() method
> > > located at CollectionAccessorFacetViaAccessor.java where the actual
> > > invocation happens.
> > >
> > > ObjectAdapter.InvokeUtils.invoke(method, pageable, owningAdapter);
> > >
> > >
> > > Thanks and best regards,
> > > Arjun Gica Manipes
> > >
> > > -----Original Message-----
> > > From: Dan Haywood [mailto:dan@haywood-associates.co.uk]
> > > Sent: Thursday, February 09, 2017 2:53 PM
> > > To: users@isis.apache.org
> > > Subject: Re: Apply pagination to collection (parented list)
> > >
> > > Hi Arjun,
> > > and welcome to the mailing list.
> > >
> > > Sounds like you've already delved quite a bit into the framework's
> > > inner workings - that's nice to see!
> > >
> > > It's not going to be possible to do pagination this way, I'm afraid,
> > > though there is pagination support already available, implemented at
> > > the UI layer rather than in the domain layer.
> > >
> > > I was about to say that providing a Pageable as an arg will fail
> > > because JDO/Datanucleus expects there to be a regular getter/setter
> > > to populate the collection (assuming it's a regular "parented"
> > > collection), but actually that's wrong - DN can just use the
> > > underlying
> > instance field.
> > >
> > > So, yes, the issue really is that getXxx(Pageable) isn't part of the
> > > Apache Isis framework's coding conventions (aka programming model);
> > > as you've uncovered it's current implementation ignores any getters
> > > that takes args.
> > > There's perhaps an argument that it should throw an exception
> > > flagging the fact that a getter with an arg is invalid.  By all
> > > means raise a ticket on that if you wish via our JIRA... should be
> easy to implement.
> > >
> > > My question to you is, with getXxx(Pageable), what would be
> > > responsible for populating the Pageable object?
> > >
> > > Meantime, to do pagination the way we currently have it designed,
> > > using @CollectionLayout#paged [1]
> > >
> > > HTH
> > > Dan
> > >
> > > [1]
> > > http://isis.apache.org/guides/rgant.html#_rgant-CollectionLayout_pag
> > > ed
> > >
> > >
> > >
> > > On Thu, 9 Feb 2017 at 01:12 Arjun Gica Manipes
> > > <manipes.ag@sprobe.com>
> > > wrote:
> > >
> > > > Hi Dan,
> > > >
> > > > I'm quite new to Apache ISIS. And I am trying to apply pagination
> > > > to Collections (parented list).
> > > > What I am trying to do is to add extra parameter to the default
> > > > getter method of the collection.
> > > >
> > > > @Collection(editing = Editing.DISABLED)
> > > > @CollectionLayout(defaultView = "table") @Getter private
> > > > List<Person> members = new ArrayList<>();
> > > >
> > > > The default getter method is:
> > > > public List<Person> getMembers() { ...
> > > > }
> > > >
> > > > I am trying to do this,
> > > > public List<Person> getMembers(final Pageable pageable) { ...
> > > > }
> > > > Pageable contains parameters needed for pagination such us
> > > > pageNumber, pageSize and etc.
> > > >
> > > > But the problem is it's not recognize as its getter because it has
> > > > a parameter.
> > > > So far, we have found out that the newly created method with
> > > > parameter is remove via findAndRemoveCollectionAccessors() method
> > > > located at CollectionAccessorFacetViaAccessorFactory.java
> > > >
> > > > Any idea or suggestion for its implementation?
> > > >
> > > >
> > > > Thanks and best regards,
> > > > Arjun Gica Manipes
> > > >
> > > >
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message