Open new window by POST using h:commandButton

旧时模样 提交于 2019-11-27 14:26:46

The only non-JS way is to set target="_blank" in the parent <h:form>.

<h:form target="_blank">
    ...
    <h:commandButton value="Open in new Window" />
</h:form>

This however affects all non-ajax(!) actions which are performed in the very same form. So if you're smart, make the action which shouldn't open in a new window an ajax action. However, ajax is also JavaScript and you mentioned that you don't want to use JS (I hope you don't get shocked once you discover that PrimeFaces is actually full of JavaScript).

If you absolutely need to restrict it to a single action, then you really can't go around asking little help to JavaScript.

<h:form>
    ...
    <h:commandButton value="Open in new Window" onclick="this.form.target='_blank'" />
</h:form>

When you restrict the target only to a single action, maybe you want to get the form in its initial state. With the oncklick action you set the target of the form to a _blan page. After the click, the page is opened in a new tab/page (triggers the action event). At last, the onblur action is triggered and set the form again to its initial state (the rest of the buttons will open in the _self page) With this code, you can restrict to only a h:commandbutton to open in a new page. The rest of the buttons will be opened in the self page:

    <h:commandButton
       onclick="this.form.target='_blank'"
       onblur="this.form.target='_self'"
       id="listadoRebuts"
       action="#{giaquaBusquedaCorte.abrirListadoRebuts}"
       value="#{msg.seqVisorbtnRecibos}">
    </h:commandButton>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!