【问题标题】:Primefaces and RemoteCommand: Best pratice to handle parameters from JavaScript [closed]Primefaces 和远程命令:处理来自 JavaScript 的参数的最佳实践 [关闭]
【发布时间】:2012-11-21 07:30:51
【问题描述】:

我已经定义了两个这样的 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中定义的(它们是从JavaScript通过rc1或rc2传递的),如果可以在action中直接读取参数,那么就不需要actionListener。

对此的最佳做法是什么:在 actionListener 上或直接在操作中读取参数?为什么?

【问题讨论】:

    标签: javascript jquery jsf jsf-2 primefaces


    【解决方案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" />
    

    【讨论】:

      猜你喜欢
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2014-11-28
      • 2010-09-07
      • 2011-04-14
      • 2011-05-30
      相关资源
      最近更新 更多