2014-04-24 23 views
2

我嘗試使用從autoComplete組件中的選定頁面對象獲取的鏈接在新窗口(或選項卡)中呈現新頁面。 嘗試多個選項後,我認爲唯一的機會是使用JavaScript來抓取提交,觸發一個遠程命令,它給了我一個JavaScript頁面對象的鏈接屬性的JavaScript調用。p:remoteCommand在ajax響應中返回<eval>兩次

JSF-Snipplet(在自動完成降低屬性)

<h:form id="autoCompleteForm"> 
    <p:autoComplete id="autoComplete" widgetVar="autoCompleteWidget" value="#{pageBean.selectedPage}" /> 
    <p:remoteCommand action="#{pageBean.showPage}" name="showPage" /> 
</h:form> 

一些JS:

// form submit 
('#autoCompleteForm').on('submit', function(e) { 
          e.preventDefault(); 
          showPage(); 
         }); 
// open link 
var openLink = function(pageLink) { 
    window.open(pageLink, '_blank'); 
}; 

豆一部分行動

public void showPage() { 
    RequestContext context = RequestContext.getCurrentInstance(); 
    context.execute("openLink('" + selectedPage.getLink() + ".xhtml')"); 
} 

一切工作起來不錯,但響應包含兩次eval標籤。

<partial-response> 
<changes> 
<update id="javax.faces.ViewState"><![CDATA[2851816213645347690:-2276123702509360418]]></update> 
<eval><![CDATA[openLink('target.xhtml');]]></eval> 
<eval><![CDATA[openLink('target.xhtml');]]></eval> 
</changes> 
</partial-response> 

我試圖重定向或返回視圖名稱不同的方法,但所有導致沒有令人滿意的解決方案(例如,URL不改變或沒有新的窗口)。

回答

0

問題解決了: 我曾在我的臉上,配置之前定義PrimePartialViewContextFactory

<factory> 
    <partial-view-context-factory>org.primefaces.context.PrimePartialViewContextFactory</partial-view-context-factory> 
</factory> 

通過消除它的應用程序的行爲像預期。

這也解決了在DataTable中分頁和排序的問題(JSON.parse: unexpected non-whitespace character after JSON data)。