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
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).