-
1. Re: Call a method and redirect browser afterwards
danielc.roth Feb 22, 2008 5:14 PM (in response to m23)This works for me. I don't know if is the correct Seam way though...
<h:commandButton action="#{someBean.dothis}"/>
and
@Name("someBean") public class SomeBean { @In(value = "org.jboss.seam.faces.facesContext") private FacesContext context; public void dothis() { // do your stuff ((HttpServletResponse) context.getExternalContext().getResponse()).sendRedirect("/some/Servlet"); } }
-
2. Re: Call a method and redirect browser afterwards
keithnaas Feb 22, 2008 5:19 PM (in response to m23)There may be ways to do this using the basic Seam stuff, but the ExternalContext in JSF simply fronts the Servlet apis.
In order to redirect, you should be able to call FacesContext.getCurrentInstance().getExternalContext().redirect(
/somewhere/that/isnot/jsf
)Within a Seam managed component, you could even inject the FacesContext and then cut out the call to getCurrentInstance().
-
3. Re: Call a method and redirect browser afterwards
danielc.roth Feb 22, 2008 5:23 PM (in response to m23)That looks a bit nicer, no casting and stuff. :-)
-
4. Re: Call a method and redirect browser afterwards
m23 Feb 26, 2008 8:41 AM (in response to m23)Thanks a lot Keith and Daniel!
Unfortunately I just ran into the next problem...
The servlet to which the method redirects is configured in web.xml to maintain the seam contexts (Seam Servlet Filter).The whole thing works if i just provide an outputLink on the webpage. I'm able to access data from the conversation context within the Servlet:
<h:outputLink value="/some/Servlet?conversationId=#{conversation.id}&conversationIsLongRunning=true" />
But if I do the following within my method, my conversation context seems to be empty:
FacesContext.getCurrentInstance().getExternalContext().redirect("/some/Servlet?conversationId=#{conversation.id}&conversationIsLongRunning=true")
Am I wrong to assume that this should actually be working?
Thank you in advance for your answers!Michael
-
5. Re: Call a method and redirect browser afterwards
mars1412 Feb 26, 2008 10:12 AM (in response to m23)what about seams @Redirect annotation?
-
6. Re: Call a method and redirect browser afterwards
hubaghdadi Feb 26, 2008 1:53 PM (in response to m23)I never tried it but maybe you would like to give org.jboss.seam.faces.redirect a shot.
-
7. Re: Call a method and redirect browser afterwards
pmuir Feb 27, 2008 12:13 PM (in response to m23)Try
FacesContext.getCurrentInstance().getExternalContext().redirect("/some/Servlet?conversationId=" + Conversation.instance().getId() + "&conversationIsLongRunning=true");