ok, somewhat belated getting back to you on this post.  (I'll review your
other later ones, but I can explain this one at least...)

First off, I actually found an issue even getting to this point; in
TransportPath I had to change:

-    public void setLegs(ArrayList<ShortLeg> legs) {

to:

+    public void setLegs(List<ShortLeg> legs) {

otherwise the JDO enhancement didn't work for me.

(I also needed to fix some pom.xml dependencies).

Anyway, with those changes made, I reproduced your issue.

To explain why it worked if one entry in the table, but not if two, it is
to do with the fact that a table with one entry is automatically
re-rendered as an entity, and this is done by a redirect.  This redirect
gives the chance for the persist of the entities that has been queued up in
the xactn but not yet applied to be completed.

When there is >1 entity in the table, however, what we seem to have is a
list that is rendering two entities where persist(...) has been called on
them (in the ShortestPathService), but where that persist hasn't yet been
done because the xactn is not yet executed.  Thus, in
EntityModel#createPageParameters(final ObjectAdapter adapter), the
persistent variable is false, and thus the oid is not added to the link.

You can see this if you look at the hyperlink of those two entities in the
table; they have a title and a type, but no oid.

Fortunately the fix is straight-forward: make a call to "container.flush()"
in the SPS (or in the TransportDemands service that delegates to it):

    @NotInServiceMenu
    @ActionSemantics(Of.SAFE)
    public List<TransportPath> planAlternatives(final TransportDemand
demand){
        List<TransportPath> shortestPaths = sps.getShortestPaths(demand);
        getContainer().flush();
        return shortestPaths;
    }

This then renders those two TransportPath entities correctly.

OK, let me go look at your other posts, see what other points they were
raising...

Dan


On 10 February 2013 11:30, Christian Steinebach <
[email protected]> wrote:

> Hi again,
>
> I simplified th getShortestPath to just generate some fake objects.
> A TransportPath is displayed with legs when only one TransportPath is added
> When adding several tp's the list is displayed in a table, but clicking on
> a title
> crashes the UI.
>
> public class ShortestPathService extends AbstractService {
>
>     @Hidden
>     public List<TransportPath> getShortestPaths(TransportDemand td) {
>         List<TransportPath> l = new ArrayList<TransportPath>();
>
>         // if j == 1, i.e. only one element in l, then it works
>         // otherwise crash in shown table
>
>         for (int j = 0; j < 2; j++) {
>             TransportPath tp = newTransientInstance(TransportPath.class);
>             for (int i = 0; i < 2; i++) {
>                 ShortLeg sl = newTransientInstance(ShortLeg.class);
>                 sl.setFrom("from " + i + j);
>                 sl.setTo("to " + i + j);
>                 persist(sl);
>                 tp.addLeg(sl);
>             }
>             persist(tp);
>             l.add(tp);
>         }
>         return l;
>         //return getShortestPaths(td.getPickup(), td.getDelivery());
>     }
>
> The exception:
>
>     [exec] ERROR - DefaultExceptionMapper     - Unexpected error occurred
>      [exec] org.apache.wicket.WicketRuntimeException: Can't instantiate
> page using constructor 'public
> org.apache.isis.viewer.wicket.ui.pages.entity.EntityPage(org.apache.wicket.request.mapper.parameter.PageParameters)'
> and argument 'pageType=[ENTITY], pageTitle=[from 00-to 00-to 10]'. Might be
> it doesn't exist, may be it is not visible (public).
>      [exec]     at
> org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:193)
> ....
> ...
> ...
>     [exec]      ... 40 more
>      [exec] Caused by: java.lang.NullPointerException
>      [exec]     at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
>      [exec]     at java.util.regex.Matcher.reset(Matcher.java:291)
>
>                   Christian
>
>
>
>
>
>
>
> ________________________________________
> From: Christian Steinebach [[email protected]]
> Sent: Sunday, February 10, 2013 11:38 AM
> To: [email protected]
> Subject: Presenting the user with alternatives to select one...
>
> Hi everybody!
>
> I'm working on a similar demo as DDDsample (didn't know about it until you
> started the discussion)
> I have a service installed which should produces a list of alternative
> transportation paths from a pickup
> to a delivery destination. One of the alternatives should be selected by
> the user.
> The chosen TransportationPath should then be added to a TransportDemand.
>
> class TransportPath[{
>    List<ShortLeg> getLegs();
> ...
> }
> //for simplicity only to and from
> class ShortLeg{
>     public String getFrom();
>     public String getTo();
> }
>
> The ShortestPathService seems to work ok while generating
> TransportPaths with increasing 'costs'. When 'leaving' the service all
> legs are instantiated.
> Nothing needs to be persisted until the user has chosen an alternative.
>
> Now the questions:
>
> 1) While generating the paths I've used createTransientInstance() with
> persist and without persist afterwords.
> I've use new ...() as well to allocate both new paths and new ShortLegs.
>
> Whenever the transport paths end up in a table, the legs are gone, the
> list is empty.
> I've build up the title on the fly to check that the legs are originally
> added tot the transport path.
> And the title is reflecting all legs correctly, but still the added legs
> are gone.
> When clicking on one alternative, the viewer crashes.
>
> What am I doing wrong here? What would be the correct way of presenting
> unpersisted
> alternatives to a user where he can select the one.
>
> 2) Even when having a list of transport paths (althouhg only titles) where
> should I annotate with
> @Bulk to make it happen? I've tried several places (TransportDemand,
> TransportDemands)
> but to no success. Or isn't Bulk the right way to do it?
>
> I'm getting more and more confused and am obviously missing something
> important here.
>
> I've put the source on GitHub
> https://github.com/chris58/TPM.git
>
>            Any help very much appriciated
>                  Christian
>
>
> I've tried the onaboat project to get some ideas, but when clicking on an
> 'Undefined Schedule' in Voyage
> it crashes too. :-(
>
>
>
>
>

Reply via email to