Redirect to home page after login seam 3 - seam3

I have custom Authenticator and I want to redirect to home page after successfully authenticate in seam 3 . How can i do that ??

There are a few ways to do this.
The simplest way is to return "/home.xhtml"; in your login action.

Other way is use navigation rule in faces-config.xml:
<navigation-rule>
<from-view-id>/loginPage.xhtml</from-view-id>
<navigation-case>
<from-action>#{authBean.login}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/homePage.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-action>#{authBean.login}</from-action>
<from-outcome>fail</from-outcome>
<to-view-id>/loginPage.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>

Related

Unable to parse document faces-config.xml

StackTrace:
Severe: Exception while loading the app
Severe: Undeployment failed for context /CS230_Projekat_StefanJankovic_3750
Severe: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: com.sun.faces.config.ConfigurationException: Unable to parse document 'jndi:/server/CS230_Projekat_StefanJankovic_3750/WEB-INF/faces-config.xml': null
And my faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="https://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://xmlns.jcp.org/xml/ns/javaee
https://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<navigation-rule>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>admin</from-outcome>
<to-view-id>/admin.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
I really dont know what to do. First I was getting null pointer exception for one of my method and now this.

How to Redirect in Liferay Portal using JSF

what is the way to redirect to another page inside the portlet in liferay using jsf? I have been trying window.location.href through javascript but it tries to redirect the page not the portal.
It depends on to which page you want to redirect to.
Redirection to first page of another portlet.
Suppose you have portlet1 and from portlet1 you want to redirect to portlet2. If the URL of portlet2 is http:/yourDomain/web/portal/portlet2 then below code will redirect to first page of portlet2 from portlet1
FacesContext context = FacesContext.getCurrentInstance();
javax.faces.context.ExternalContext externalContext = context.getExternalContext();
externalContext.redirect("/web/portal/portlet2");
Above code will hit portlet2 and depending on your welcome page configuration (in phaselistener or in portlet.xml your first page will gets displayed.
Redirecting to some other page (instead of welcome page) of Portlet2 from Portlet1.
Lets say you want to redirect to 3rd page of your Portlet2 from Portlet1. In this case, using the above code you can hit Portlet2. This will invoke PhaseListenter. Here you can check which page you want to redirect to and accordingly use below code.
if(someConditionIsMet)
{
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot newPage = context.getApplication().getViewHandler().createView(context,"/your3rdPage.jsf");
context.setViewRoot(newPage);
context.renderResponse();
}
Redirecting to some page in the same Portlet
I think you are not looking answer for this case. Still, I assume as I am not fully clear about your question.
Lets say you are invoking a link through h:commandLink or h:commandButton. And you are invoking a method(which returns String). Then below code can be used.
public String someMethod()
{
//Do your checks here
return "success";
}
This has to be configured in your faces-config.xml file.
<navigation-rule>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/yourRequiredPage.jsf</to-view-id>
</navigation-case>
</navigation-rule>

JSF preRenderView not triggered when navigating to page without using Redirect

I have created a preRender method to be called when the user navigate to that specific page, I use:
<f:metadata>
<f:event listener="#{targetClass.prerender()}"
type="preRenderView">
</f:event>
</f:metadata>
but the problem is that this method is not being called when I navigate to this page, unless I use
<redirect />
in the faces-config.xml file.
But, I don't want to use redirect, so the url always point to the login page.
Thank you.

Spring MVC Simple Redirect Controller Example

Hi I'm trying to compare the redirect methods of various frameworks.
I've made it through quite a few:
Cakephp
CodeIgniter
Django
Grails
Rails
Zend Framework
However I'm stuck trying to create the simplest example possible for Spring MVC and JSF.
What I want is either one or two controllers which handle the /index and /redirect urls where /index simply links to /redirect, and /redirect uses a 301 redirect to redirect back to /index.
I found this documentation, I just don't have the persistence to figure out how to create this seemingly simple example in Spring MVC.
Thanks!
Just incase I played with redirect in JSF and SPring MVC:
JSF:
<navigation-rule>
<from-view-id>index.xhtml</from-view-id>
<navigation-case>
<from-action>#{actionController.actionSubmitted}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>index.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
Spring-MVC submitting user form in POST/REdirect/GET design pattern:
#RequestMapping(value="/index.html", method=RequestMethod.GET)
public ModelAndView index(){
ModelAndView mv = new ModelAndView("index");
User user = new User();
mv.addObject("user", user);
return mv;
}
#RequestMapping(value="/signin.html",method = RequestMethod.POST)
public ModelAndView submit(#Valid User user){
ModelAndView mv = new ModelAndView("redirect:index.html");
System.out.println(user.getFirstName());
return mv;
}
Hope it helps.

JSF Page Navigation: Unexpected RuntimeException

I have the following navigation rules defined in faces-config.xml. I am able to navigate to second page, however from second page to first, I am not able to navigate. What could the reason, anything wrong with navigation rules? I would like to do navigation without redirect.
JSF version is 1.1
<navigation-rule>
<from-view-id>/first.jspx</from-view-id>
<navigation-case>
<from-action>#{bean.setSelectedItem}</from-action>
<from-outcome>form1</from-outcome>
<to-view-id>/second.jspx</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/second.jspx</from-view-id>
<navigation-case>
<from-action>#{bean2.testBack}</from-action>
<from-outcome>form2</from-outcome>
<to-view-id>/first.jspx</to-view-id>
</navigation-case>
</navigation-rule>
From firebug I could see the following exception
java.lang.RuntimeException: no message available
Thanks
Update 1
Code in my second.jspx to return back to first.jspx
<ice:form id="form2">
<ice:commandLink action="#{bean.testBack}">
<h:outputText value="Test" />
</ice:commandLink>
</ice:form>
Code when I click the action
public String testBack() {
try {
logger.info("invoked");
} catch (Exception e) {
e.printStackTrace();
}
return "form2";
}
Stacktrace
java.lang.RuntimeException: no message available
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:173)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230)
at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33)
at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NullPointerException
at com.icesoft.faces.context.DOMResponseWriter.enhanceAndFixDocument(DOMResponseWriter.java:315)
at com.icesoft.faces.context.DOMResponseWriter.endDocument(DOMResponseWriter.java:186)
at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:496)
at com.icesoft.faces.application.D2DViewHandler.renderView(D2DViewHandler.java:153)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:16)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:114)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:66)
at com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:28)
at com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
at com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:160)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher$1.service(SessionDispatcher.java:42)
at com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.service(ThreadBlockingAdaptingServlet.java:18)
at com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.service(EnvironmentAdaptingServlet.java:63)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:62)
at com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:22)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:153)
you can try this: (I copied this from my project so please change the values ;-) )
<navigation-rule>
<from-view-id>/pages/registration.jspx</from-view-id>
<navigation-case>
<from-outcome>next</from-outcome>
<to-view-id>/pages/registration.jspx</to-view-id>
</navigation-case>
<navigation-rule>
or is there any specific reason why you use this tag?
<from-action>#{bean.setSelectedItem}</from-action>

Resources