我尝试使用从autoComplete组件中的选定页面对象获得的链接在新窗口(或选项卡)中呈现新页面。 在尝试多个选项之后,我认为唯一的机会是使用javascript来捕获提交,触发一个远程命令,它使用来自页面对象的链接属性进行javascript调用。
JSF-Snipplet(autoComplete中的属性减少)
<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');
};
Bean部分行动
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>
我尝试了重定向或返回视图名称的不同方法,但这些都导致没有令人满意的解决方案(例如,网址没有更改或没有新窗口)。
答案 0 :(得分:0)
问题解决了:
我之前在faces-config中定义了PrimePartialViewContextFactory
:
<factory>
<partial-view-context-factory>org.primefaces.context.PrimePartialViewContextFactory</partial-view-context-factory>
</factory>
通过删除它,应用程序就像预期的那样。
这也解决了DataTables中的分页和排序问题(JSON.parse: unexpected non-whitespace character after JSON data
)。