You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by bogdan_cm <bo...@rbccm.com> on 2012/06/17 04:10:24 UTC

InjectPage into a service

Hi everyone, 
   Is there a way to inject a page into a service via InjectPage annotation?

I am trying the following and does not seem to work:

package com.myapp.services;
public class MyServiceImpl implements MyService
{

@InjectPage
private Login loginPage;

  public Object consumer()
{
  loginPage.getLoginForm().recordError("too-soon-change-email");
  return loginPage;
}
...
}


So, myPage get's MyService injected and calls consumer() method. When
consumer() tries to  getLoginForm() is throws null pointer. 
=======================================
I also tried passing to the service consumer() method a loginPage instance
injected in "myPage" as an argument, like this:

public MyPage
{
@InjectPage
private Login loginPage;

@Inject
private MyService worker;

onActivate()
{
  worker.consume(workToBeDone, loginPage);
}

}

In this case I get a more "exotic" error. 


Any ideas how I could make use of a page in a service? 


Thanks very much, 
Bogdan. 





--
View this message in context: http://tapestry.1045711.n5.nabble.com/InjectPage-into-a-service-tp5713950.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: InjectPage into a service

Posted by bogdan_cm <bo...@rbccm.com>.
Understood. Thanks for the reply. 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/InjectPage-into-a-service-tp5713950p5713956.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: InjectPage into a service

Posted by Taha Siddiqi <ta...@gmail.com>.
Hi

Trying to access a page from a service is an anti-pattern. Tapestry doesn't allow it. 

You should throw an exception in your service layer and do the presentation stuff (like redirecting or recording an error etc) in the pages(presentation layer).

regards
Taha

On Jun 17, 2012, at 7:40 AM, bogdan_cm wrote:

> Hi everyone, 
>   Is there a way to inject a page into a service via InjectPage annotation?
> 
> I am trying the following and does not seem to work:
> 
> package com.myapp.services;
> public class MyServiceImpl implements MyService
> {
> 
> @InjectPage
> private Login loginPage;
> 
>  public Object consumer()
> {
>  loginPage.getLoginForm().recordError("too-soon-change-email");
>  return loginPage;
> }
> ...
> }
> 
> 
> So, myPage get's MyService injected and calls consumer() method. When
> consumer() tries to  getLoginForm() is throws null pointer. 
> =======================================
> I also tried passing to the service consumer() method a loginPage instance
> injected in "myPage" as an argument, like this:
> 
> public MyPage
> {
> @InjectPage
> private Login loginPage;
> 
> @Inject
> private MyService worker;
> 
> onActivate()
> {
>  worker.consume(workToBeDone, loginPage);
> }
> 
> }
> 
> In this case I get a more "exotic" error. 
> 
> 
> Any ideas how I could make use of a page in a service? 
> 
> 
> Thanks very much, 
> Bogdan. 
> 
> 
> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/InjectPage-into-a-service-tp5713950.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org