jsf - p :remoteCommand returns <eval> twice in ajax response

标签 jsf primefaces

我尝试使用从自动完成组件中的选定页面对象获得的链接在新窗口(或选项卡)中呈现新页面。 在尝试了多个选项之后,我认为唯一的机会是使用 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/

相关文章:

jsf - 异常 - 无法为托管 Bean 凭据设置属性 userLogin

jsf - 使用 "Please select"f :selectItem with null/empty value inside a p:selectOneMenu

javascript - 使用 Javascript 确定 JSF 库资源

jsf - 阻止 p :commandButton displayed on a p:confirmDialog in addition to displaying a dynamic message on the dialog

validation - 仅当验证通过时才使用 ajax 有条件地渲染组件

html - 从 primefaces 表中的一列中删除边框的问题

jsf - p :dataTable with p:cellEditor tab behaviour

css - 如何隔离 PrimeFaces Widget 不受主站点 CSS 的影响

jsf - 类型 'org.primefaces.model.TreeNode'没有类型参数

jquery - 使用 Return/Enter 键将编辑的单元格保存在 Primefaces 3.4 单元格内可编辑数据表中