• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how we forward a JSF page into Servlet

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am new to JSF , I have a problem how to forward a JSF page into Sevlet. Same thing i will be used in jsp means it is very easy through (form action="") but in JSF there is no "form action ". Any body knows please reply
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JSF page can link to any kind of target, including servlets. However a JSF FORM is expected to talk to JSF. That's because you're getting fields populated from JSF and JSF manages a cycle of repeated validations and error displays until the user either gets the data clean enough to use of abandons the page. JSF also carries a lot of freight that other platforms don't want/need/understand.

In order to submit a form to a servlet, it has to be a non-JSF form, so you usually are going to find life simpler if the form page is completely non-JSF - a straight JSP, servlet-generated HTML, Struts, or whatever. Since you normally pre-load data into a form, this usually means that the JSF action processor that takes you there is going to have to do a forwarding operation to invoke the form setup code.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Client Side

- You can embed the resource (with can either be a servlet or a resource), but you have the pass the parameters in the traditional way.

Server Side

- You can either perform a redirect or a dispatch

## redirect
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext ec = facesContext.getExternalContext();
ec.redirect(url)

## dispatch
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext ec = facesContext.getExternalContext();
ec.dispatch(url)

In essence, ExternalContext object serves as your window to non jsf resources.

I hope this helps.
 
Ranch Hand
Posts: 42
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can some body please tell me what to put in url. the actual URL or just the path of class file specifiled in servlet mapping in web.xml

thanks a lot
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic