问题
My h:commandLink is opening/previewing the pdf document on same page/window when h:commandlink used with target="_blank". I want it to be opened in new tab of the browser
where can be the error?
Preview.xhtml code:
<h:commandLink id="DocUpoadPreview" action="#{documentController.previewUploadedFile}" value="Preview" target="_blank" >
</h:commandLink>
In previewuploadedFile() action encription/decryption and some other process with pdf is required that is why necessary to use and that is why not using h:outputlink here. After the action process i want to redirect to another page(previewUploadedDoc.xhtml) which uses primefaces p:media tag to preview the document.
public String previewUploadedFile() throws Exception {
//decryption process and adding water mark here//
FacesContext.getCurrentInstance().getExternalContext()
.redirect("previewUploadedDoc.xhtml");}
回答1:
Try it:
<h:commandLink id="DocUpoadPreview" action="#{documentController.previewUploadedFile}" value="Preview" target="_new" />
回答2:
target="_new" is not valid value of target. It defines _new as a name of new page.
This is the valids values: https://www.w3schools.com/tags/att_a_target.asp
来源:https://stackoverflow.com/questions/14066973/target-blank-in-hcommandlink-not-opening-page-in-new-tab-of-browser