target=“_blank” in h:commandlink not opening page in new tab of browser

余生长醉 提交于 2020-01-14 12:32:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!