how to call a JSF from a servlet

i got a problem during development.Using RequestDispatcher i am able to forward request to JSP page.But i am not able to forward request to JSF page.Can any one help me?
[176 byte] By [mydevelopmentforuma] at [2007-11-26 21:40:55]
# 1
Please explain "not able". What's happening? Got any errors? Also show a small reproduceable code snippet.
BalusCa at 2007-7-10 3:25:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I have attached a doPost method that forwards to a jsf page and passes url parameters.

public void doPost(HttpServletRequest request, HttpServletResponse response)

{

//Get parameters

String qcType = request.getParameter("qcType");

String system = request.getParameter("system");

String manco = request.getParameter("manco");

String id = request.getParameter("id");

String qcUser = request.getParameter("qcUser");

//Outcome

String outcome = "SUCCESS";

String logMessage = "Servlet request:" + "\n\tqcType: " + qcType + "\n\tsystem: " + system + "\n\tmanco: " + manco + "\n\tid: " + id + "\n\tqcUser: " + qcUser;

LOG.debug(logMessage);

/*

* Set up faces. Code sourced from

* http://wiki.apache.org/myfaces/InvokingJsfPagesWithStandardUrls

*/

LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);

Lifecycle lifecycle = lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);

FacesContextFactory fcFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);

FacesContext facesContext = fcFactory.getFacesContext(getServletContext(), request, response, lifecycle);

Application application = facesContext.getApplication();

ViewHandler viewHandler = application.getViewHandler();

try

{

// specify what page you want to pretend to "come from"

String viewId = "/ParameterServlet";

UIViewRoot view = viewHandler.createView(facesContext, viewId);

facesContext.setViewRoot(view);

//Set up parameter and data form

QCParameterForm parameters = (QCParameterForm) application.createValueBinding("#{QCParameterForm}").getValue(facesContext);

QCDataForm data = (QCDataForm) application.createValueBinding("#{QCDataForm}").getValue(facesContext);

//Set parameters

parameters.setId(id);

parameters.setManco(manco);

parameters.setQcType(qcType);

parameters.setQcUser(qcUser);

parameters.setSystem(system);

//Load data form

data.setParameters(parameters);

data.load();

//Specify what action and outcome value you want to use for navigation

String action = "submit";

NavigationHandler navigationHandler = application.getNavigationHandler();

navigationHandler.handleNavigation(facesContext, action, outcome);

lifecycle.render(facesContext);

}

catch(Exception ex)

{

...

}

}

I hope this helps

Jam1ea at 2007-7-10 3:25:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Never mind the bully there,and i think i know what you mean,

The web.xml file should have the faces servlet in

it along with any other servlets. It should be mapped

in servlet-mapping to /faces path or you can map it to

pages by *.faces servlet-mapping

The first means you need to have your application path

first but then include /faces after it in the url and the second

means that you have an extension of the file not .jsp but

have .faces

so

/MyTomcatApp/faces/somejsppage.jsp

(any problem with this one try keeping all JSF pages in a folder

called "faces")

or

/MyTomcatApp/myjsfpage.faces

note: redirect urls are relative only don't put the domain in

and if you want to get an outside domain you "print" a special

"location: ;" CGI header using the output wrapper(IETF RFC's

for CGI).

nicephotoga at 2007-7-10 3:25:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Sorry, slight bungle there from me , this bit:....servlet-mapping to /faces path or you......should read:servlet-mapping to /faces/* path or you"with an asterix/star" in it to indicate any pagesymbol naming scheme following it.
nicephotoga at 2007-7-10 3:25:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...