I'm working at a jsf application that at a certain time need to open an external page in a new tab, leaving the first page active. I need to find a way to make the application perform, in a single button click:
- a redirect to an external URL in a new tab
- an action which disables the button itself in the original page
I've tried using an <outputLink />
but it has no action attribute.
I've tried using a <commandLink />
but it's unable to redirect outside.
I've also tried a <commandLink />
with target="_blank"
and a redirection coded in the backing bean:
<h:commandLink onclick="submit();" target="_blank" action="#{myBean.execute}" disabled="#{myBean.linkDisabled}" value="external link" />
and, in the backing bean:
public String execute() {
linkDisabled = true;
try{
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.redirect(Constants.EXTERNAL_URL);
} catch(Exception e){
throw new FacesException("Redirection failed");
}
return THIS_PAGE;
}
A page is opened in a new tab but it's the current page instead of the that with URL Constants.EXTERNAL_URL
and the button is still enabled. No error message is shown. Any suggestion?
Thanks in advance, Andrea