【问题标题】:p:remoteCommand returns <eval> twice in ajax responsep:remoteCommand 在 ajax 响应中返回 <eval> 两次
【发布时间】:2014-04-24 14:07:33
【问题描述】:

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

我尝试了不同的重定向或返回视图名称的方法,但这一切都导致没有令人满意的解决方案(例如,URL 没有改变或没有新窗口)。

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    问题已解决: 我之前在 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)。

    【讨论】:

      猜你喜欢
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 2015-05-04
      • 2013-06-03
      • 2015-01-02
      相关资源
      最近更新 更多