• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how we forward a JSF page into Servlet

 
Vimal Bharathi Andiappan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18282
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • 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.
 
Mahendra Pratap
Ranch Hand
Posts: 42
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic