3

我已经定义了两个这样的 RemoteCommand:

<p:remoteCommand name="rc1" actionListener="#{rcBean.rcActionListener1}" action="#{rcBean.rcAction1}" />

<p:remoteCommand name="rc2" action="#{rcBean.rcAction2}" />

Javascript 方法使用如下参数调用 rc1 和 rc2:

rc1({a:'value for a', b:'value for b'});

rc2({a:'value for a', b:'value for b'});

而rcBean的rcActionListener和rcAction是:[rcBean部分代码]

protected String param_a, param_b;

protected void processRcParams() {
    FacesContext context = FacesContext.getCurrentInstance();
    Map map = context.getExternalContext().getRequestParameterMap();
    param_a = (String) map.get("a");
    param_b = (String) map.get("b");
}

public void rcActionListener1() {
    processRcParams();
}

public void rcAction1() {
    //-> parameters setted
    //-> process something...
}

public void rcAction2() {
    //-> parameters not set yet, and so
    processRcParams();
    //-> process something...
}

判断参数不是直接在p:remoteCommand中定义的(它们是通过rc1或者rc2从JavaScript传过来的),如果可以在action中直接读取参数,那么就不需要actionListener。

最佳实践是什么:在 actionListener 上或直接在动作中读取参数?为什么?

4

1 回答 1

1
<script type="text/javascript">
            //<![CDATA[
            function test(){
                document.getElementById('hiddenurlpage').value = "test1";
                lazyload();

            }
                //]]>
        </script>
<h:inputHidden id="hiddenurlpage" value="#{userBean.currentpage}"/>
<p:remoteCommand name="lazyload"  process="@this,hiddenurlpage" />
于 2013-01-03T13:55:29.630 回答