You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by VIJAY SONAWANE <vi...@yahoo.co.in> on 2008/12/05 10:37:44 UTC

How to redirect page in JSF

Hi all,

I am new to JSF.
           I am facing one problem of url redirecting.
i.e.  if user enters url like this
                     http://myserver/project1/viewers/   
then he/she redirected to default page http://myserver/project1/viewers/viewersHome.html page.

note : all my pages are in xhtml 

thanks in advance 

Vj++


      Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/

Re: How to redirect page in JSF

Posted by Gerhard Petracek <ge...@gmail.com>.
hello,

there are several alternatives.
the following approach is just for the requested use-case.

sample url: http://localhost:8080/faces/subdirectory/

in web.xml add a servlet-mapping for the faces servlet:
sample:
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>

then you can implement a phase listener for PhaseId.RESTORE_VIEW

in the method beforePhase you check if the target is a valid path - e.g.:
  FacesContext facesContext = phaseEvent.getFacesContext();
  if(facesContext.getExternalContext().getRequestPathInfo() != null &&
     ! facesContext.getExternalContext().getRequestPathInfo().contains("."))
{
     //implement default page handling
  }

@implement default page handling:
if you would like to use always the same page for the complete application:
  UIViewRoot uiViewRoot =
facesContext.getApplication().getViewHandler().createView(facesContext,
"/subdirectory/directory_default.xhtml");
  facesContext.setViewRoot(uiViewRoot);
  facesContext.renderResponse();

*or* if you would like to provide or calculate a default source + use
navigation rules:
  facesContext.setViewRoot(getSourceView(phaseEvent));

facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext,
null, "directory_default");
  facesContext.renderResponse();

you have to implement the method getSourceView. if it returns e.g.:
/subdirectory/nav_source.xhtml

you have to add the following navigation-rule to your faces config:
  <navigation-rule>
    <from-view-id>/subdirectory/nav_source.xhtml</from-view-id>
    <navigation-case>
      <from-outcome>directory_default</from-outcome>
      <to-view-id>/subdirectory/directory_default.xhtml</to-view-id>
    </navigation-case>
 </navigation-rule>

regards,
gerhard



2008/12/5 mariyappa b <ma...@gmail.com>

> I even have the same requirement but I want to do with Navigation rule.
>
> Thank you,
> Mariyappa
>
>
> On Fri, Dec 5, 2008 at 3:41 PM, VIJAY SONAWANE <vi...@yahoo.co.in>wrote:
>
>> Thanks for reply Anton,
>>
>>
>>
>>           what I am trying to do is when user only enters url upto the
>> folder name where the actual page to be displayed is present
>> Example: I have folder  User in my project structure.
>>  So now if the user wants to access the page which is in this folder but
>> by mistake if the user doesn't provide the page name in the URL,but provides
>> till the folder where the page is included in ( i.e .
>> http://myserver/users/ )
>> then it should show page  http://myserver/users/userhome.html.
>>
>>
>>
>> ------------------------------
>> *From:* Anton Gavazuk <an...@gmail.com>
>> *To:* MyFaces Discussion <us...@myfaces.apache.org>
>> *Sent:* Friday, 5 December, 2008 3:22:16 PM
>> *Subject:* Re: How to redirect page in JSF
>>
>> Hi
>> I dont understand you problem,
>>
>> what are you expecting?
>>
>> redirect in jSF could be done for example in navigation rules in faces
>> config file.
>>
>> 2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>:
>> > Hi all,
>> >
>> > I am new to JSF.
>> >            I am facing one problem of url redirecting.
>> > i.e.  if user enters url like this
>> >                      http://myserver/project1/viewers/
>> > then he/she redirected to default page
>> > http://myserver/project1/viewers/viewersHome.html page.
>> >
>> > note : all my pages are in xhtml
>> >
>> > thanks in advance
>> >
>> > Vj++
>> >
>> >
>> >
>> > ________________________________
>> > Add more friends to your messenger and enjoy! Invite them now.
>>
>> ------------------------------
>> Be the first one to try the new Messenger 9 Beta! Click here.<http://in.rd.yahoo.com/tagline_messenger_7/*http://in.messenger.yahoo.com/win/>
>>
>
>
>
>
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: How to redirect page in JSF

Posted by mariyappa b <ma...@gmail.com>.
I even have the same requirement but I want to do with Navigation rule.

Thank you,
Mariyappa

On Fri, Dec 5, 2008 at 3:41 PM, VIJAY SONAWANE <vi...@yahoo.co.in>wrote:

> Thanks for reply Anton,
>
>
>
>           what I am trying to do is when user only enters url upto the
> folder name where the actual page to be displayed is present
> Example: I have folder  User in my project structure.
>  So now if the user wants to access the page which is in this folder but by
> mistake if the user doesn't provide the page name in the URL,but provides
> till the folder where the page is included in ( i.e .
> http://myserver/users/ )
> then it should show page  http://myserver/users/userhome.html.
>
>
>
> ------------------------------
> *From:* Anton Gavazuk <an...@gmail.com>
> *To:* MyFaces Discussion <us...@myfaces.apache.org>
> *Sent:* Friday, 5 December, 2008 3:22:16 PM
> *Subject:* Re: How to redirect page in JSF
>
> Hi
> I dont understand you problem,
>
> what are you expecting?
>
> redirect in jSF could be done for example in navigation rules in faces
> config file.
>
> 2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>:
> > Hi all,
> >
> > I am new to JSF.
> >            I am facing one problem of url redirecting.
> > i.e.  if user enters url like this
> >                      http://myserver/project1/viewers/
> > then he/she redirected to default page
> > http://myserver/project1/viewers/viewersHome.html page.
> >
> > note : all my pages are in xhtml
> >
> > thanks in advance
> >
> > Vj++
> >
> >
> >
> > ________________________________
> > Add more friends to your messenger and enjoy! Invite them now.
>
> ------------------------------
> Be the first one to try the new Messenger 9 Beta! Click here.<http://in.rd.yahoo.com/tagline_messenger_7/*http://in.messenger.yahoo.com/win/>
>

Re: How to redirect page in JSF

Posted by Anton Gavazuk <an...@gmail.com>.
Hmm,
cool requirement :)

ok - on first thoughts - you can handle somehow "not found event" (for
example by overriding default ErrorHandler in MyFaces config) and do
with NavigationHandler needed forward/redirect

for example - in Errorhandler you have access to FacesContext

class YOurErrorHandler{


//determine to which view you should go when requested file/view not found
//get navigationHandler
navigationHandler.handleNavigation(context, null, nameOfneededRootView);

}

and put for every such case in faces config such thing
<navigation-case>
         <from-outcome>nameOfneededRootView</from-outcome>
         <to-view-id>blablabla.jsp</to-view-id>
         <redirect/>
 </navigation-case>

Hope it will help

2008/12/5 Gerhard Petracek <ge...@gmail.com>:
> hello,
>
> with jsp:
>
> web.xml
>     <welcome-file-list>
>         <welcome-file>index.jsp</welcome-file>
>     </welcome-file-list>
>
> then you can place an index.jsp file in the target folder
> sample content:
> <%@ page session="false"%>
> <%
>   response.sendRedirect("directory_default_page.jsf");
> %>
>
> or with html:
>
> web.xml
>     <welcome-file-list>
>         <welcome-file>index.html</welcome-file>
>     </welcome-file-list>
>
> then you can place an index.html file in the target folder
> sample content:
> <html>
>   <head>
>     <meta http-equiv="refresh" content="0; URL=directory_default_page.jsf">
>   </head>
> </html>
>
> as anton mentioned:
> please don't use it instead of navigation rules.
>
> regards,
> gerhard
>
>
>
> 2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>
>>
>> Thanks for reply Anton,
>>
>>
>>
>>           what I am trying to do is when user only enters url upto the
>> folder name where the actual page to be displayed is present
>> Example: I have folder  User in my project structure.
>>  So now if the user wants to access the page which is in this folder but
>> by mistake if the user doesn't provide the page name in the URL,but provides
>> till the folder where the page is included in ( i.e .http://myserver/users/
>> )
>> then it should show page  http://myserver/users/userhome.html.
>>
>>
>>
>> ________________________________
>> From: Anton Gavazuk <an...@gmail.com>
>> To: MyFaces Discussion <us...@myfaces.apache.org>
>> Sent: Friday, 5 December, 2008 3:22:16 PM
>> Subject: Re: How to redirect page in JSF
>>
>> Hi
>> I dont understand you problem,
>>
>> what are you expecting?
>>
>> redirect in jSF could be done for example in navigation rules in faces
>> config file.
>>
>> 2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>:
>> > Hi all,
>> >
>> > I am new to JSF.
>> >            I am facing one problem of url redirecting.
>> > i.e.  if user enters url like this
>> >                      http://myserver/project1/viewers/
>> > then he/she redirected to default page
>> > http://myserver/project1/viewers/viewersHome.html page.
>> >
>> > note : all my pages are in xhtml
>> >
>> > thanks in advance
>> >
>> > Vj++
>> >
>> >
>> >
>> > ________________________________
>> > Add more friends to your messenger and enjoy! Invite them now.
>>
>> ________________________________
>> Be the first one to try the new Messenger 9 Beta! Click here.
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>

Re: How to redirect page in JSF

Posted by Gerhard Petracek <ge...@gmail.com>.
hello,

with jsp:

web.xml
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

then you can place an index.jsp file in the target folder
sample content:
<%@ page session="false"%>
<%
  response.sendRedirect("directory_default_page.jsf");
%>

or with html:

web.xml
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

then you can place an index.html file in the target folder
sample content:
<html>
  <head>
    <meta http-equiv="refresh" content="0; URL=directory_default_page.jsf">
  </head>
</html>

as anton mentioned:
please *don't* use it instead of navigation rules.

regards,
gerhard



2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>

> Thanks for reply Anton,
>
>
>
>           what I am trying to do is when user only enters url upto the
> folder name where the actual page to be displayed is present
> Example: I have folder  User in my project structure.
>  So now if the user wants to access the page which is in this folder but by
> mistake if the user doesn't provide the page name in the URL,but provides
> till the folder where the page is included in ( i.e .
> http://myserver/users/ )
> then it should show page  http://myserver/users/userhome.html.
>
>
>
> ------------------------------
> *From:* Anton Gavazuk <an...@gmail.com>
> *To:* MyFaces Discussion <us...@myfaces.apache.org>
> *Sent:* Friday, 5 December, 2008 3:22:16 PM
> *Subject:* Re: How to redirect page in JSF
>
> Hi
> I dont understand you problem,
>
> what are you expecting?
>
> redirect in jSF could be done for example in navigation rules in faces
> config file.
>
> 2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>:
> > Hi all,
> >
> > I am new to JSF.
> >            I am facing one problem of url redirecting.
> > i.e.  if user enters url like this
> >                      http://myserver/project1/viewers/
> > then he/she redirected to default page
> > http://myserver/project1/viewers/viewersHome.html page.
> >
> > note : all my pages are in xhtml
> >
> > thanks in advance
> >
> > Vj++
> >
> >
> >
> > ________________________________
> > Add more friends to your messenger and enjoy! Invite them now.
>
> ------------------------------
> Be the first one to try the new Messenger 9 Beta! Click here.<http://in.rd.yahoo.com/tagline_messenger_7/*http://in.messenger.yahoo.com/win/>
>



-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: How to redirect page in JSF

Posted by VIJAY SONAWANE <vi...@yahoo.co.in>.
Thanks for reply Anton,

       
    
          what I am trying to do is when user only enters url upto the folder name where the actual page to be displayed is present 
Example: I have folder  User in my project structure.
 So now if the user wants to access the page which is in this folder but by mistake if the user doesn't provide the page name in the URL,but provides till the folder where the page is included in ( i.e .http://myserver/users/ )
then it should show page  http://myserver/users/userhome.html.






________________________________
From: Anton Gavazuk <an...@gmail.com>
To: MyFaces Discussion <us...@myfaces.apache.org>
Sent: Friday, 5 December, 2008 3:22:16 PM
Subject: Re: How to redirect page in JSF

Hi
I dont understand you problem,

what are you expecting?

redirect in jSF could be done for example in navigation rules in faces
config file.

2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>:
> Hi all,
>
> I am new to JSF.
>            I am facing one problem of url redirecting.
> i.e.  if user enters url like this
>                      http://myserver/project1/viewers/
> then he/she redirected to default page
> http://myserver/project1/viewers/viewersHome.html page.
>
> note : all my pages are in xhtml
>
> thanks in advance
>
> Vj++
>
>
>
> ________________________________
> Add more friends to your messenger and enjoy! Invite them now.



      Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/

RE: How to redirect page in JSF

Posted by "Nutulapati, Krishna" <KN...@ussco.com>.
 
You can do this from backing bean. 
Give a control from that jsf to backing bean, through hidden field. 
In backing bean, you can add code some thing like this. 

FacesContext.getCurrentInstance().getExternalContext().redirect("/contex
troot/jsfpagename.faces");

-----Original Message-----
From: Anton Gavazuk [mailto:antongavazuk@gmail.com] 
Sent: Friday, December 05, 2008 3:52 AM
To: MyFaces Discussion
Subject: Re: How to redirect page in JSF

Hi
I dont understand you problem,

what are you expecting?

redirect in jSF could be done for example in navigation rules in faces
config file.

2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>:
> Hi all,
>
> I am new to JSF.
>            I am facing one problem of url redirecting.
> i.e.  if user enters url like this
>                      http://myserver/project1/viewers/ then he/she 
> redirected to default page 
> http://myserver/project1/viewers/viewersHome.html page.
>
> note : all my pages are in xhtml
>
> thanks in advance
>
> Vj++
>
>
>
> ________________________________
> Add more friends to your messenger and enjoy! Invite them now.

Re: How to redirect page in JSF

Posted by Anton Gavazuk <an...@gmail.com>.
Hi
I dont understand you problem,

what are you expecting?

redirect in jSF could be done for example in navigation rules in faces
config file.

2008/12/5 VIJAY SONAWANE <vi...@yahoo.co.in>:
> Hi all,
>
> I am new to JSF.
>            I am facing one problem of url redirecting.
> i.e.  if user enters url like this
>                      http://myserver/project1/viewers/
> then he/she redirected to default page
> http://myserver/project1/viewers/viewersHome.html page.
>
> note : all my pages are in xhtml
>
> thanks in advance
>
> Vj++
>
>
>
> ________________________________
> Add more friends to your messenger and enjoy! Invite them now.