我尝试使用从自动完成组件中的选定页面对象获得的链接在新窗口(或选项卡)中呈现新页面。 在尝试了多个选项之后,我认为唯一的机会是使用 javascript 来捕获提交,触发远程命令,这会给我一个带有页面对象链接属性的 javascript 调用。
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');
};
用于操作的 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>
我尝试了不同的重定向或返回 View 名称的方法,但都没有得到令人满意的解决方案(例如,URL 未更改或没有新窗口)。
最佳答案
问题解决:
我之前在 faces-config 中定义了 PrimePartialViewContextFactory
:
<factory>
<partial-view-context-factory>org.primefaces.context.PrimePartialViewContextFactory</partial-view-context-factory>
</factory>
通过删除它,应用程序会像预期的那样运行。
这也解决了数据表中的分页和排序问题(JSON.parse:JSON 数据后意外的非空白字符
)。
关于jsf - p :remoteCommand returns <eval> twice in ajax response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23271332/