You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by DaveFunkyJam <da...@yahoo.co.uk> on 2009/08/29 14:03:16 UTC

Querying request URL from within Tapestry 5

Hi there. I have a Tapestry 5 application which manages data for many clubs.
I would like the application to show club information depending on the URL
that is typed in.

Eg. If you enter "localhost:8080/MyApp/Club1" ...then the app should strip
out the end of the requst url (Club1), do a lookup in the database for the
club, and add this to the session. Then all database requests can look up
data depending on which club is in the session.

If you enter "localhost:8080/MyApp/Club2", you get club to registered in the
session, and all database requests are for club 2.

Do you know if there is an easy way to do this? 

Many thanks.

Tapestry 5 rocks.

-- 
View this message in context: http://www.nabble.com/Querying-request-URL-from-within-Tapestry-5-tp25202317p25202317.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: Querying request URL from within Tapestry 5

Posted by newtonik <ne...@gmail.com>.
Hey, 
I am not sure if you understood what Christian said, but in the code below,
the last part of the url gets passed as a parameter to the onActivate
function. You do have to do any string manipulation of the url. You can just
get integer. 

So when you are enter to the page class below, thanks to to tapestry club =
Club2;
"localhost:8080/MyApp/Club2"

public class MyApp {
void onActivate(String club) {

System.out.println("Club is " + club);
//prints out "Club is Club2"

}



}

Newton



DaveFunkyJam wrote:
> 
> Genuis! I did something like this and it works. I've put the code below.
> I've spent ages trying to get this to work in Struts without any success
> since iand Tapestry does it simply and easily. Tapestry kicks ass!
> 
> Many thanks.
> 
> 
> Heres the code...
> 
> public class Index {
> 
> 	@Inject
> 	@Service("RequestGlobals")
> 	private RequestGlobals requestGlobals;
> 
> 	void onActivate(String id) {
> 
> 		String servletPath =
> requestGlobals.getHTTPServletRequest().getServletPath();
> 		String requestedClub = servletPath.substring(1);
> 		int indexOfFirstSlash = requestedClub.indexOf("/");
> 		if(indexOfFirstSlash > -1) {
> 			requestedClub = requestedClub.substring(0, requestedClub.indexOf("/"));
> 		}
> 		
> 		System.out.println("### requestedClub: " + requestedClub);
> 
> 		//now send club to club page...
> 
> 	}
> 	
> 	
> }
> 

-- 
View this message in context: http://www.nabble.com/Querying-request-URL-from-within-Tapestry-5-tp25202317p25208942.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: Querying request URL from within Tapestry 5

Posted by DaveFunkyJam <da...@yahoo.co.uk>.
Genuis! I did something like this and it works. I've put the code below. I've
spent ages trying to get this to work in Struts without any success since
iand Tapestry does it simply and easily. Tapestry kicks ass!

Many thanks.


Heres the code...

public class Index {

	@Inject
	@Service("RequestGlobals")
	private RequestGlobals requestGlobals;

	void onActivate(String id) {

		String servletPath =
requestGlobals.getHTTPServletRequest().getServletPath();
		String requestedClub = servletPath.substring(1);
		int indexOfFirstSlash = requestedClub.indexOf("/");
		if(indexOfFirstSlash > -1) {
			requestedClub = requestedClub.substring(0, requestedClub.indexOf("/"));
		}
		
		System.out.println("### requestedClub: " + requestedClub);

		//now send club to club page...

	}
	
	
}
-- 
View this message in context: http://www.nabble.com/Querying-request-URL-from-within-Tapestry-5-tp25202317p25202854.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: Querying request URL from within Tapestry 5

Posted by Christian Riedel <ch...@gmx.net>.
Hi,

create a page named club (...pages.Club and a Club.tml).
In Club.java:

public class Club
{
    void onActivate(long id) {
        // whatever you like
    }
}

Now you can send the id or name or whatever you like to the page by 
requesting the url ...YourApp/Club/123

Regards
Christian


DaveFunkyJam schrieb:
> Hi there. I have a Tapestry 5 application which manages data for many clubs.
> I would like the application to show club information depending on the URL
> that is typed in.
>
> Eg. If you enter "localhost:8080/MyApp/Club1" ...then the app should strip
> out the end of the requst url (Club1), do a lookup in the database for the
> club, and add this to the session. Then all database requests can look up
> data depending on which club is in the session.
>
> If you enter "localhost:8080/MyApp/Club2", you get club to registered in the
> session, and all database requests are for club 2.
>
> Do you know if there is an easy way to do this? 
>
> Many thanks.
>
> Tapestry 5 rocks.
>
>   

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