Primefaces und RemoteCommand: Best pratice zu handhaben Parameter von JavaScript

Ich habe zwei RemoteCommand wie diese:

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

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

Wird die Javascript-Methode aufrufen, rc1 und rc2 mit Parametern:

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

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

Und die rcBean rcActionListener und rcAction ist: [rcBean Teil code]

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...
}

Beurteilen, dass der Parameter nicht definiert sind, direkt in p:remoteCommand (Sie bestanden aus JavaScript über rc1 oder rc2), wenn die Parameter gelesen werden können, direkt in der Handlung, dann der actionListener ist nicht erforderlich.

Was ist die beste Praxis für diese: Lesen Sie die Parameter vor, auf die actionListener oder direkt in die Aktion? und Warum?

InformationsquelleAutor D.Souza | 2012-12-03
Schreibe einen Kommentar