views:

109

answers:

2

i want a mechanism in my web app as described below:

user will enter mydomain.com/CompanyName , depending upon the CompanyNameit will show its logo and its customized page, and i will take that parsed parameter in session again upon each request i will compare the parsed CompanyName and one stored in session , and if they matched then application will show the requested page with user's data.else it will be redirected to login page. and the main thing is i want this thing in JSF arch.

i tried taking a servlet that will resolve all request and it will parse and then will dispatch the request to prefered servlet,but problem is it goes in loop as again it resolves to the same controller servlet,

+3  A: 

You can do this via a phase listener. You can define a global one in faces-config.xml (or using annotations, if JSF 2.0 is used)

<lifecycle>
    <phase-listener>com.yourcompany.CompanyPhaseListener</phase-listener>
</lifecycle>

There you have access to the FacesContext, from which you can obtain the current request URI. Parse it and store the appropriate attributes in the request, which you can later read on your pages.

The phase listener is executed on the specified phase(s), and perhaps you should choose RENDER_RESPONSE

For affecting the way your URLs appear in the browser, check PrettyFaces.

Bozho
but the problem here is,how can i achieve mydomain.com/something/companyname/pages/somepage.jsf pattern ?the URL in browser must include companyName .
org.life.java
as a note - why don't you use a subdomain, i.e. - `companyname.yourdomain.com` (and see my update)
Bozho
no i want to handle it using URL pattern only, can't we just manage it using JSF only, without preetyFaces?
org.life.java
i tried pretty faces, it works fine except in a case, where the view is resolved from faces-config.xml then the URL pattern won't be the required one,i means using pretty faces we can resolve view from pattern but what when i resolve view from faces-config.xml and i want my desired URL pattern ?
org.life.java
here i have attached the sample application i have created using prettyFaces,access this URL.yourserver:port/MavenJSFSample/companyName/loginclick buttonit wi get theyourserver:port/MavenJSFSample/companyName/home.jsfi want some thing likeyourserver:port/MavenJSFSample/companyName/homehttp://www.4shared.com/file/M9h7dt9S/MavenJSFSample.html]MavenJSFSample.zip
org.life.java
PrettyFaces does work, but you need to use the built-in navigation: http://ocpsoft.com/docs/prettyfaces/snapshot/en-US/html_single/#navigation.actions
Lincoln
+1  A: 

i tried taking a servlet that will resolve all request and it will parse and then will dispatch the request to prefered servlet,but problem is it goes in loop as again it resolves to the same controller servlet,

Use a Filter instead. It by default doesn't listen on forwarded requests, so you won't get an infinite loop on forwarding.

BalusC
thats what pretty faces does,using this pattern i am facing a problem, it works fine except in a case, where the view is resolved from faces-config.xml then the URL pattern won't be the required one, i means using pretty faces we can resolve view from pattern but what when i resolve view from faces-config.xml and i want my desired URL pattern ?
org.life.java
here i have attached the sample application i have created using prettyFaces,access this URL.http://yourserver:port/MavenJSFSample/companyName/loginclick buttonit wi get thehttp://yourserver:port/MavenJSFSample/companyName/home.jsfi want some thing likehttp://yourserver:port/MavenJSFSample/companyName/homehttp://www.4shared.com/file/M9h7dt9S/MavenJSFSample.html]MavenJSFSample.zip
org.life.java
BalusC expecting for your comment.
org.life.java