Jsf p:remoteCommand在异步模式下不工作

Jsf p:remoteCommand在异步模式下不工作,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,如果有人能在这里帮助我,我将不胜感激 我在页面上有一个选项卡式布局,通过单击选项卡(p:commandLink),我希望为该选项卡初始化适当的数据,并更新显示内容的区域。由于我希望初始化延迟进行(当呈现选项卡内容时),所以我使用Primefaces的p:remoteCommand 问题是,当我将p:remoteCommand设置为异步工作(async=true)时,此功能不工作,不会调用action方法。当属性“async”为false时,它会工作 例如: <html xmlns="htt

如果有人能在这里帮助我,我将不胜感激

我在页面上有一个选项卡式布局,通过单击选项卡(p:commandLink),我希望为该选项卡初始化适当的数据,并更新显示内容的区域。由于我希望初始化延迟进行(当呈现选项卡内容时),所以我使用Primefaces的p:remoteCommand

问题是,当我将p:remoteCommand设置为异步工作(async=true)时,此功能不工作,不会调用action方法。当属性“async”为false时,它会工作

例如:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>

<f:view contentType="text/html">
    <h:form id="peopleForm">
        <h:panelGroup id="panel1">
            #{testbean.message}
        </h:panelGroup>

        <p:remoteCommand name="lazyInit"
            onstart="console.log('calling init')"
            action="#{testbean.init()}" 
            update=":peopleForm:panel1"
            async="true"
         />

        <script>
        $(function(){
            console.log('before call');
            lazyInit();
            console.log('after call');
        });
        </script>
    </h:form>

    <p:commandLink update=":peopleForm" value="Tab1" action="#{testbean.setMenuSelected('Tab1')}"/>

    <p:commandLink update=":peopleForm" value="Tab2" action="#{testbean.setMenuSelected('Tab2')}"/>
</f:view>
</html>

@ManagedBean(name = "testbean")
@Component("testbean")
@Scope("session")
public class TestBean implements Serializable {

    private static final long serialVersionUID = -2760060999550263904L;

    private String message;
    private String menuSelected = "Tab1";

    public void init() {
        if (menuSelected.equals("Tab1")) {
            message = "Tab1";
        }
        if (menuSelected.equals("Tab2")) {
            message = "Tab2";
        }
    }

    public String getMessage() {
        return message;
    }

    public String getMenuSelected() {
        return menuSelected;
    }

    public void setMenuSelected(String menuSelected) {
        this.menuSelected = menuSelected;
    }
}

#{testbean.message}
$(函数(){
log('before call');
lazyInit();
log('after call');
});
@ManagedBean(name=“testbean”)
@组件(“testbean”)
@范围(“会议”)
公共类TestBean实现了可序列化{
私有静态最终长serialVersionUID=-2760060999550263904L;
私有字符串消息;
私有字符串menuSelected=“Tab1”;
公共void init(){
if(menuSelected.equals(“Tab1”)){
message=“Tab1”;
}
if(menuSelected.equals(“Tab2”)){
message=“Tab2”;
}
}
公共字符串getMessage(){
返回消息;
}
公共字符串getMenuSelected(){
选择返回菜单;
}
public void setMenuSelected(字符串menuSelected){
this.menuSelected=menuSelected;
}
}
当async=“true”不起作用时,在单击链接时不会调用testbean.init()方法。当'async'为false时,它会工作

我不确定“异步”是否适用于这种类型的用例,或者我误解了它

背景: 在我的应用程序中,我实际上有多个区域需要在选项卡更改时更新。每个区域都有自己的初始化方法,可以从数据库中提取适当的数据。我希望异步调用这些初始化方法的原因是我不希望其他初始化方法等待第一个方法完成,然后第二个方法完成等。所有这些方法都是相互独立的,因此它们之间没有同步的理由。最终,这将加快向用户显示页面内容的速度


谢谢你的帮助

我遇到了完全相同的问题,通过将
p:remoteCommand
替换为隐藏的
p:commandLink
解决了这个问题。然后没有
name
属性,因此需要使用JavaScript来单击链接

(...)

<h:head>
    <script>
        function lazyInitClick() {
            $("[id$='lazyInit']").click();
        }
    </script>
</h:head>

(...)

<h:form>
    <p:commandLink id="lazyInit" actionListener="#{testbean.init()}" async="true" style="display: none;" />
    <h:outputScript>lazyInitClick()</h:outputScript>
</h:form>

(...)
(…)
函数lazyInitClick(){
$(“[id$='lazyInit']”)。单击();
}
(...)
lazyInitClick()
(...)