You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Kambiz Darabi <da...@m-creations.com> on 2016/10/05 19:28:37 UTC

Re: Calling repository methods from a Wicket page

Hi Dan,

thanks a lot. Works like a charm.

Cheers


Kambiz

On 2016-09-30 09:46 CEST, Dan Haywood <da...@haywood-associates.co.uk> wrote:

> Hi Kambiz,
>
> You are pretty close... you can use getIsisSessionFactory().doInSession(...)
>
> there's an example in the RegisterPanel, a component of the Wicket
> RegistrationPage.html / .java  [1], ie:
>
> getIsisSessionFactory().doInSession(new Runnable() {
>         @Override
>         public void run() {
>             final UserRegistrationService userRegistrationService =
> getIsisSessionFactory()
>
> .getServicesInjector().lookupService(UserRegistrationService.class);
>
>             getIsisSessionFactory().getCurrentSession().getPersistenceSession().getTransactionManager()
>                     .executeWithinTransaction(new TransactionalClosure() {
>                 @Override
>                 public void execute() {
>                     userRegistrationService.registerUser(userDetails);
>                     removeAccountConfirmation();
>                 }
>             });
>         }
>     });
>
>
> HTH
> Dan
>
> [1]
> https://github.com/apache/isis/blob/rel/isis-1.13.0/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/pages/accmngt/register/RegisterPanel.java#L127
>
>
>
> On 29 September 2016 at 22:08, Kambiz Darabi <da...@m-creations.com> wrote:
>
>> Hi,
>>
>> in one of our applications, we have a Wicket page which is mounted onto
>> a context path and streams a video resource to the calling client, based
>> on some page parameters.
>>
>> Up to now, this page uses http calls to the RO viewer to perform the
>> domain-related validations, lookups etc.
>>
>> I would like to access the repositories and services directly, which are
>> available through getServicesInjector().lookupService(Class), but such
>> calls end in NPEs, because the persistence session is null.
>>
>> PageAbstract has a getPersistenceSession() method which throws an NPE,
>> as
>>
>> getIsisSessionFactory().getCurrentSession()
>>
>> seems to return null.
>>
>> Is there something special I need to perform prior to using
>> getPersistenceSession() ?
>>
>> Thanks
>>
>>
>> Kambiz
>>