I thought about using flash scope to save the previous site uri to allow back redirection on the target site.
On the main site ajax calls a bean method to save the current URI in the flash and navigate to the target sub site provided as an parameter.
On the sub site a simple navigate method from the bean is called using the previously stored uri from the flash.
Here is the problem:
The data in the flash is empty, but when i print it out on the site its correct.
Sub site
#{flash.PREVIOUS_URI}
<h:form>
<h:commandLink value="Redirect from flash"
action="#{bean.navigate(flash.PREVIOUS_URI)}"/>
</h:form>
public String navigate(final String outcome)
{
return outcome;
}
Is the flash.PREVIOUS_URI in the action call evaluated on the next request resulting in the flash value being empty?
Or how do i save it as a var on the site to make it work? <c:set> seems not to work.
The
actionattribute of<h:commandLink>is evaluated during invoke action phase of the postback request and not during the render response phase of the initial request, as you seemed to expect. Thus, the flash scoped attribute would not be available anymore during invoking the action.Your best bet is to pass it as
<f:param>instead:You can get it by
@ManagedProperty("#{param.previousURI}"),<f:viewParam name="previousURI">, orExternalContext#getRequestParameterMap().Alternatively, if this is really all you basically have (and you basically don’t need to perform any business action), then you could also just use
<h:link>instead.This way the
<h:form>is not needed and you also end up with a fullworthy<a>element which is bookmarkable and searchbot-indexable.