Re: Does the onActivate method can't return a Page?
It send a redirect response in my test because of the default value of SUPPRESS_REDIRECT_FROM_ACTION_REQUEST is false. I guess the same is true of you,you can see the network action to verify it in FireFox with Firebug. Mark W. Shead 写道: > I use this all the time and it works. For example: > > @InjectPage > private Login loginPage; > > Object onActivate() { > if(!userExists) { > > loginPage.setNext(this.getClass()); > return loginPage; > } > return null; > } > > Is what I use to redirect to a login page if a user isn't logged in. > > Mark > > On Dec 24, 2008, at 9:59 AM, d0ng wrote: > >> Hi, >> I have a page that's used to redirect request to other page in some >> case,but I don't make it work well. >> For example,in the test code the Index page can't be render and there is >> nothing to output. >> >> public class Test { >> @InjectPage >> private Index index; >> >> public Object onActivate() { >> return index; >> } >> } >> >> Does anyone know why? >> >> Thanks. >> >> - >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> > > - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Does the onActivate method can't return a Page?
I use this all the time and it works. For example: @InjectPage private Login loginPage; Object onActivate() { if(!userExists) { loginPage.setNext(this.getClass()); return loginPage; } return null; } Is what I use to redirect to a login page if a user isn't logged in. Mark On Dec 24, 2008, at 9:59 AM, d0ng wrote: Hi, I have a page that's used to redirect request to other page in some case,but I don't make it work well. For example,in the test code the Index page can't be render and there is nothing to output. public class Test { @InjectPage private Index index; public Object onActivate() { return index; } } Does anyone know why? Thanks. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Does the onActivate method can't return a Page?
It seems to me the default on that should be true. I certainly would want to give permission for suppression of my redirects rather than having that be the default! :) Bill in Austin On Fri, Dec 26, 2008 at 12:47 PM, d0ng wrote: > I got it. > > The different behavior of this question may be cause by the setting of > SymbolConstants.SUPPRESS_REDIRECT_FROM_ACTION_REQUESTS. > > In my developing product,the value of > SUPPRESS_REDIRECT_FROM_ACTION_REQUESTS is set to true,then the response is > empty. > > When I set it to false,the response is correct. > > Is this a problem? > > BTW,I'm using 5.0.18. > > Thanks. > > > > > Bill Holloway ??: > > I set up just such a page, and have it working. It returns my index just >> fine. I'm using 5.0.18, JDK 1.5, Jetty 6.1.8. >> >> Bill >> >> On Fri, Dec 26, 2008 at 8:24 AM, d0ng wrote: >> >> >> >>> Thanks for your reply. >>> >>> But I find a comment "The activate event handler may also return a value, >>> which is treated identically to a return value of a component event >>> request >>> event trigger. This will typically be used in an access validation >>> scenario." >>> from the page http://tapestry.apache.org/tapestry5/guide/pagenav.html . >>> >>> The return value of a component event request event trigger could be a >>> page >>> instance,should I think the same as activate event? >>> >>> Thanks. >>> >>> >>> >>> >>> >>> >>> Bill Holloway ??: >>> >>> My guess is that the page activation context isn't designed for this. >>> >>> There are a couple of workarounds. One would be to inject the Response service (org.apache.tapestry5.services.Response) into your page class and then use it to perform the redirection in your onActivate method: @Inject private Response _response; void onActivate () { _response.sendRedirect("/some/other/page"); } Cheers, Bill On Wed, Dec 24, 2008 at 9:59 AM, d0ng wrote: > Hi, > I have a page that's used to redirect request to other page in some > case,but I don't make it work well. > For example,in the test code the Index page can't be render and there > is > nothing to output. > > public class Test { > @InjectPage > private Index index; > > public Object onActivate() { > return index; > } > } > > Does anyone know why? > > Thanks. > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > > > > > >>> >>> >> >> >> > >
Re: Does the onActivate method can't return a Page?
I got it. The different behavior of this question may be cause by the setting of SymbolConstants.SUPPRESS_REDIRECT_FROM_ACTION_REQUESTS. In my developing product,the value of SUPPRESS_REDIRECT_FROM_ACTION_REQUESTS is set to true,then the response is empty. When I set it to false,the response is correct. Is this a problem? BTW,I'm using 5.0.18. Thanks. Bill Holloway ??: I set up just such a page, and have it working. It returns my index just fine. I'm using 5.0.18, JDK 1.5, Jetty 6.1.8. Bill On Fri, Dec 26, 2008 at 8:24 AM, d0ng wrote: Thanks for your reply. But I find a comment "The activate event handler may also return a value, which is treated identically to a return value of a component event request event trigger. This will typically be used in an access validation scenario." from the page http://tapestry.apache.org/tapestry5/guide/pagenav.html . The return value of a component event request event trigger could be a page instance,should I think the same as activate event? Thanks. Bill Holloway ??: My guess is that the page activation context isn't designed for this. There are a couple of workarounds. One would be to inject the Response service (org.apache.tapestry5.services.Response) into your page class and then use it to perform the redirection in your onActivate method: @Inject private Response _response; void onActivate () { _response.sendRedirect("/some/other/page"); } Cheers, Bill On Wed, Dec 24, 2008 at 9:59 AM, d0ng wrote: Hi, I have a page that's used to redirect request to other page in some case,but I don't make it work well. For example,in the test code the Index page can't be render and there is nothing to output. public class Test { @InjectPage private Index index; public Object onActivate() { return index; } } Does anyone know why? Thanks. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Tapestry 5 with Spring Security - problem with unit tests.
Thanks for the reply! I came up with a similar solution: I pass SecurityModel class from tapestry-spring-security to instance of PageTester: tester = new PageTester(appPackage, appName, "src/main/webapp",SecurityModule.class); and then I just create SecurityContext (the same way like in my first post) and set it in SecurityContextHolder: SecurityContextHolder.setContext(securityContext); I don't create registry or use loadUserByUsername(...) method. However, test() method from nu.localhost.tapestry5.springsecurity.components.IfLoggedIn throws NullPointerException during executing unit test, and I had to modify it by adding (that's probably very sloppy ;-) ): if (requestGlobals.getHTTPServletRequest()==null) { if (((UserDetails)SecurityContextHolder.getContext() .getAuthentication().getDetails()).getUsername()!=null) { return true; } } Did you handle it in a better way? (That's probably in yours handleIfLogIn() method ;-) ) Mark Horn-2 wrote: > > We also use spring-security and ran into some issues as well. What we > ended up doing was adding something like this to the JUnit #setUp > method > >/* (non-Javadoc) > * @see junit.framework.TestCase#setUp() > */ >protected void setUp() throws Exception { >super.setUp(); > >_tester = new PageTester(_ROOT_PACKAGE_NAME, _APP_MODULE, >PageTester.DEFAULT_CONTEXT_PATH, TestHarnessModule.class); > >_encoder = _tester.getService(ContextPathEncoder.class); > >Registry registry = _tester.getRegistry(); >registry.performRegistryStartup(); > >UserDetailsService userDetailsSvc = > _tester.getService(UserDetailsService.class); >UserDetails ud = userDetailsSvc.loadUserByUsername(someuser); > >handleIfLogIn(); > >SecurityContext context = new SecurityContextImpl(); >Authentication currentUser = new > UsernamePasswordAuthenticationToken(ud.getUsername(), >somepassword); >context.setAuthentication(currentUser); >SecurityContextHolder.setContext(context); >} > > Hope that helps.. and if anyone has a better solution please let me know. > > -Mark > > PS (sorry for the double post, but wanted to make sure my comment was > attached to the appropriate thread) > > On Mon, Dec 22, 2008 at 10:28 AM, SergeEby wrote: >> >> Hi, >> >> This seems to be related to this thread: >> http://www.nabble.com/PageLinkTarget%2C-where-did-it-go--to21022001.html#a21022001 >> >> /Serge >> >> >> Michał Jedynak wrote: >>> >>> Hi there, >>> >>> I've integrated spring security to my sample tapestry5 application >>> (I'm using version 5.0.18) based on tapestry-spring-security >>> (http://www.localhost.nu/java/tapestry-spring-security), but now my >>> unit tests that use PageTester don't work, because there is no >>> Authentication object in SecurityContext. >>> >>> I thought about creating SecurityContext, something like: >>> >>> SecurityContext securityContext = new SecurityContextImpl(); >>> User user = new User(); >>> user.setId(1L); >>> user.setUsername("user"); >>> user.setPassword("password"); >>> UsernamePasswordAuthenticationToken token = >>> new UsernamePasswordAuthenticationToken( >>> user.getUsername(), user.getPassword(), user.getAuthorities()); >>> token.setDetails(user); >>> securityContext.setAuthentication(token); >>> >>> and adding it to the rendered page through PageTester, as it is >>> described in >>> http://tapestry.apache.org/tapestry5/guide/unit-testing-pages.html: >>> >>> PageTester tester = new PageTester(appPackage, appName, >>> "src/main/webapp"); >>> Object[] context = new Object[]{ "abc", 123 }; >>> Document doc = tester.invoke(new ComponentInvocation(new >>> PageLinkTarget("MyPage"), context)); >>> >>> However this doesn't work, ComponentInvocation is an interface and I >>> don't know how to initialize properly ComponentInvocationImpl. >>> Anyone care to help? >>> >>> >>> >>> >>> >>> -- >>> Michał Jedynak >>> >>> >> >> -- >> View this message in context: >> http://www.nabble.com/Tapestry-5-with-Spring-Security---problem-with-unit-tests.-tp21126486p21129652.html >> Sent from the Tapestry - User mailing list archive at Nabble.com. >> >> >> - >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> > > q -- View this message in context: http://www.nabble.com/Tapestry-5-with-Spring-Security---problem-with-unit-tests.-tp21126486p21176964.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Set locale using url
Hello all, I'm new to Tapestry and maybe I want to do something non-standard. I want to set locale using urls. http://www.example.com/en/./ http://www.example.com/fr/./ I also write simple filter that do setting of locale, but I need to change something that strips language from URL so Tapestry can map to right page. After that I need to change LinkFactory to generate right links? public boolean service(Request request, Response response, RequestHandler handler) throws IOException { String path = request.getPath(); Pattern p = Pattern.compile("^/([a-z]{2})/.*"); Matcher m = p.matcher(path); if (m.find()) { this.localizationSetter.setThreadLocale(new Locale(m.group(1))); } // Here change request?? return handler.service(request, response); } I'm the first who is trying this or is it already implemented? As a newbie I do not know internals of Tapestry... mod_rewrite is the last I want to use... Thank you Tomas - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Does the onActivate method can't return a Page?
I set up just such a page, and have it working. It returns my index just fine. I'm using 5.0.18, JDK 1.5, Jetty 6.1.8. Bill On Fri, Dec 26, 2008 at 8:24 AM, d0ng wrote: > Thanks for your reply. > > But I find a comment "The activate event handler may also return a value, > which is treated identically to a return value of a component event request > event trigger. This will typically be used in an access validation > scenario." > from the page http://tapestry.apache.org/tapestry5/guide/pagenav.html . > > The return value of a component event request event trigger could be a page > instance,should I think the same as activate event? > > Thanks. > > > > > > > Bill Holloway ??: > > My guess is that the page activation context isn't designed for this. >> There >> are a couple of workarounds. One would be to inject the Response service >> (org.apache.tapestry5.services.Response) into your page class and then use >> it to perform the redirection in your onActivate method: >> >> @Inject >> private Response _response; >> >> void onActivate () >> { >>_response.sendRedirect("/some/other/page"); >> } >> >> Cheers, >> Bill >> >> On Wed, Dec 24, 2008 at 9:59 AM, d0ng wrote: >> >> >> >>> Hi, >>> I have a page that's used to redirect request to other page in some >>> case,but I don't make it work well. >>> For example,in the test code the Index page can't be render and there is >>> nothing to output. >>> >>> public class Test { >>> @InjectPage >>> private Index index; >>> >>> public Object onActivate() { >>> return index; >>> } >>> } >>> >>> Does anyone know why? >>> >>> Thanks. >>> >>> - >>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >>> For additional commands, e-mail: users-h...@tapestry.apache.org >>> >>> >>> >>> >> >> >> > >
Re: Tapestry 5 with Spring Security - problem with unit tests.
We also use spring-security and ran into some issues as well. What we ended up doing was adding something like this to the JUnit #setUp method /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); _tester = new PageTester(_ROOT_PACKAGE_NAME, _APP_MODULE, PageTester.DEFAULT_CONTEXT_PATH, TestHarnessModule.class); _encoder = _tester.getService(ContextPathEncoder.class); Registry registry = _tester.getRegistry(); registry.performRegistryStartup(); UserDetailsService userDetailsSvc = _tester.getService(UserDetailsService.class); UserDetails ud = userDetailsSvc.loadUserByUsername(someuser); handleIfLogIn(); SecurityContext context = new SecurityContextImpl(); Authentication currentUser = new UsernamePasswordAuthenticationToken(ud.getUsername(), somepassword); context.setAuthentication(currentUser); SecurityContextHolder.setContext(context); } Hope that helps.. and if anyone has a better solution please let me know. -Mark PS (sorry for the double post, but wanted to make sure my comment was attached to the appropriate thread) On Mon, Dec 22, 2008 at 10:28 AM, SergeEby wrote: > > Hi, > > This seems to be related to this thread: > http://www.nabble.com/PageLinkTarget%2C-where-did-it-go--to21022001.html#a21022001 > > /Serge > > > Michał Jedynak wrote: >> >> Hi there, >> >> I've integrated spring security to my sample tapestry5 application >> (I'm using version 5.0.18) based on tapestry-spring-security >> (http://www.localhost.nu/java/tapestry-spring-security), but now my >> unit tests that use PageTester don't work, because there is no >> Authentication object in SecurityContext. >> >> I thought about creating SecurityContext, something like: >> >> SecurityContext securityContext = new SecurityContextImpl(); >> User user = new User(); >> user.setId(1L); >> user.setUsername("user"); >> user.setPassword("password"); >> UsernamePasswordAuthenticationToken token = >> new UsernamePasswordAuthenticationToken( >> user.getUsername(), user.getPassword(), user.getAuthorities()); >> token.setDetails(user); >> securityContext.setAuthentication(token); >> >> and adding it to the rendered page through PageTester, as it is >> described in >> http://tapestry.apache.org/tapestry5/guide/unit-testing-pages.html: >> >> PageTester tester = new PageTester(appPackage, appName, >> "src/main/webapp"); >> Object[] context = new Object[]{ "abc", 123 }; >> Document doc = tester.invoke(new ComponentInvocation(new >> PageLinkTarget("MyPage"), context)); >> >> However this doesn't work, ComponentInvocation is an interface and I >> don't know how to initialize properly ComponentInvocationImpl. >> Anyone care to help? >> >> >> >> >> >> -- >> Michał Jedynak >> >> > > -- > View this message in context: > http://www.nabble.com/Tapestry-5-with-Spring-Security---problem-with-unit-tests.-tp21126486p21129652.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > >
Re: PageLinkTarget, where did it go?
We also use spring-security and ran into some issues as well. What we ended up doing was adding something like this to the JUnit #setUp method /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); _tester = new PageTester(_ROOT_PACKAGE_NAME, _APP_MODULE, PageTester.DEFAULT_CONTEXT_PATH, TestHarnessModule.class); _encoder = _tester.getService(ContextPathEncoder.class); Registry registry = _tester.getRegistry(); registry.performRegistryStartup(); UserDetailsService userDetailsSvc = _tester.getService(UserDetailsService.class); UserDetails ud = userDetailsSvc.loadUserByUsername(someuser); handleIfLogIn(); SecurityContext context = new SecurityContextImpl(); Authentication currentUser = new UsernamePasswordAuthenticationToken(ud.getUsername(), somepassword); context.setAuthentication(currentUser); SecurityContextHolder.setContext(context); } Hope that helps.. and if anyone has a better solution please let me know. -Mark On Mon, Dec 22, 2008 at 3:23 PM, Michał Jedynak wrote: > > I have a similar issue: > http://www.nabble.com/Tapestry-5-with-Spring-Security---problem-with-unit-tests.-td21126486.html. > The problem is not about PageLinkTarget -> PageRenderTarget, but about the > way to properly initialize ComponentInvocationImpl. > > > > nille hammer wrote: >> >> >> Hi Mark, >> first I have to admit I am not familliar with Tapestry´s testing >> mechanisms so this information is based on browsing through the javadocs >> rather than experience. I think this is the class you are looking for: >> http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/internal/services/PageRenderTarget.html >> Hope that helps, cheers nillehammer >> >> - original Nachricht >> >> Betreff: PageLinkTarget, where did it go? >> Gesendet: Mo, 15. Dez 2008 >> Von: Mark Horn >> >>> I am in the process of updating our application from Tapestry version >>> 5.0.15 to 5.0.18 and it looks like PageLinkTarget has disappeared. We >>> have been following the Unit testing as outlined >>> http://tapestry.apache.org/tapestry5/guide/unit-testing-pages.html >>> which uses the PageLinkTarget when testing a page with a context. I >>> looked around and can't find the class or any documentation on what >>> its replacement is. >>> >>> Any help is greatly appreciated. >>> >>> Thanks, >>> Mark >>> >>> - >>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >>> For additional commands, e-mail: users-h...@tapestry.apache.org >>> >>> >> >> --- original Nachricht Ende >> >> >> - >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> >> > > -- > View this message in context: > http://www.nabble.com/PageLinkTarget%2C-where-did-it-go--tp21022001p21134364.html > Sent from the Tapestry - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > >
Re: Does the onActivate method can't return a Page?
Yes,I have tested the Index page separately,it works well when I request it. Thiago HP ??: Have you tested your Index page separately? Your code looks correct. On Wed, Dec 24, 2008 at 12:59 PM, d0ng wrote: Hi, I have a page that's used to redirect request to other page in some case,but I don't make it work well. For example,in the test code the Index page can't be render and there is nothing to output. public class Test { @InjectPage private Index index; public Object onActivate() { return index; } } Does anyone know why? Thanks. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Does the onActivate method can't return a Page?
Have you tested your Index page separately? Your code looks correct. On Wed, Dec 24, 2008 at 12:59 PM, d0ng wrote: > Hi, > I have a page that's used to redirect request to other page in some > case,but I don't make it work well. > For example,in the test code the Index page can't be render and there is > nothing to output. > > public class Test { > @InjectPage > private Index index; > > public Object onActivate() { > return index; > } > } > > Does anyone know why? > > Thanks. > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Thiago - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Does the onActivate method can't return a Page?
Thanks for your reply. But I find a comment "The activate event handler may also return a value, which is treated identically to a return value of a component event request event trigger. This will typically be used in an access validation scenario." from the page http://tapestry.apache.org/tapestry5/guide/pagenav.html . The return value of a component event request event trigger could be a page instance,should I think the same as activate event? Thanks. Bill Holloway ??: My guess is that the page activation context isn't designed for this. There are a couple of workarounds. One would be to inject the Response service (org.apache.tapestry5.services.Response) into your page class and then use it to perform the redirection in your onActivate method: @Inject private Response _response; void onActivate () { _response.sendRedirect("/some/other/page"); } Cheers, Bill On Wed, Dec 24, 2008 at 9:59 AM, d0ng wrote: Hi, I have a page that's used to redirect request to other page in some case,but I don't make it work well. For example,in the test code the Index page can't be render and there is nothing to output. public class Test { @InjectPage private Index index; public Object onActivate() { return index; } } Does anyone know why? Thanks. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Does the onActivate method can't return a Page?
My guess is that the page activation context isn't designed for this. There are a couple of workarounds. One would be to inject the Response service (org.apache.tapestry5.services.Response) into your page class and then use it to perform the redirection in your onActivate method: @Inject private Response _response; void onActivate () { _response.sendRedirect("/some/other/page"); } Cheers, Bill On Wed, Dec 24, 2008 at 9:59 AM, d0ng wrote: > Hi, > I have a page that's used to redirect request to other page in some > case,but I don't make it work well. > For example,in the test code the Index page can't be render and there is > nothing to output. > > public class Test { > @InjectPage > private Index index; > > public Object onActivate() { > return index; > } > } > > Does anyone know why? > > Thanks. > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > >