p:commandLink fails to open page in new window/tab

后端 未结 7 1461
伪装坚强ぢ
伪装坚强ぢ 2020-12-17 09:42

I\'m trying to create a link to open a new page in a different window/tab and display some msg from backing bean but fail to do it, wonder know why?

here is my xhtml

相关标签:
7条回答
  • 2020-12-17 09:52

    Both are not working so issue is not in primefaces ajax. Issue in target attribute of p:commandLink its not working...

    <p:commandLink value="New Window" ajax="false" target="_blank" action="test"/>
    
    <p:commandLink value="New Window" target="_blank" action="test"/>
    

    SO we have to use

    <h:commandLink value="New Window" target="_blank" action="test"/>
    
    0 讨论(0)
  • 2020-12-17 09:53

    like this,

    <h:link target="_blank" value="Other page" outcome="your url"></h:link>
    

    Good luck!

    0 讨论(0)
  • 2020-12-17 09:57

    I do it like this:

    <p:commandLink id="link" actionListener="#{testing.getMessage}" 
        oncomplete="popupwindow('msg.xhtml', 'newwindow');" >  
        <h:outputText value="broadcast Msg" />
    </p:commandLink>
    

    With some javascript:

    <script type="text/javascript">    
    function popupwindow(url, title) {      
        window.open(url , title, "toolbar=no, scrollbars=yes, resizable=yes, top=170, left=170, width=800, height=600");        
    }    
    </script>
    

    In this example you open a new window, hope its helps!

    0 讨论(0)
  • 2020-12-17 09:58

    like this

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
         'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
    
         <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:p="http://primefaces.org/ui">
    
    
        <h:head>
            <h:outputStylesheet library="base" name='jquery-ui-1.8.16.custom.css' />
        </h:head>
        <span style="background-color: rgb(192, 192, 192);">
          <h:form target="_blank">
            <p:commandButton value="Run" action="#{bean.createReport}"  />
          </h:form>
        </span>
        </html>
    

    see:enter link description here

    0 讨论(0)
  • 2020-12-17 10:00

    <p:commandLink> has some ajax issues, Use <h:commandLink> instead.

     <h:commandLink actionListener="#{testing.printMessage}" action="/Msg.html" target="_blank">get Msg</h:commandLink>
    

    changed <p:commandLink> to <h:commandLink> and your code is working fine.

    0 讨论(0)
  • 2020-12-17 10:08

    If you are using remotecommand then you can do like this

    <p:remoteCommand name="lookAndBookNewTab"
         process="@this" action="#{lookAndBookMB.onPageLoadForNewTab()}"
         rendered="#currentUserManager.
         hasPermission('LookAndBook','View')}"             update=":messageForm:growl" />
    

    And my javascript:

    <script> 
        if(event.ctrlKey &amp;&amp; event.shiftKey &amp;&amp; event.keyCode == 119) {
         lookAndBookNewTab(); 
        event.preventDefault();
    </script>
    

    ServerSide action method:

    public String onPageLoadForNewTab(){
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); String url = req.getRequestURL().toString();
            url=(url.substring(0, url.length() - req.getRequestURI().length()) + req.getContextPath() + "/"); url=url+navigationpagename+".jsf"; RequestContext.getCurrentInstance().
            execute("window.open('"+url+"','_blank')");** 
        return ""; }
    
    0 讨论(0)
提交回复
热议问题