Je veux transmettre la valeur à remoteCommand
partir de javascript. Si cela est possible, comment puis-je le faire et comment puis-je les recevoir dans le haricot de soutien ?
Réponses
Trop de publicités?
Joel
Points
1087
Jonathan L
Points
1
Combinez @BalusC @Joel's post pour un exemple fonctionnel
<h:form>
<p:remoteCommand name="rcName" update="msgs" actionListener="#{remoteCommandView.beanMethod}" />
<p:growl id="msgs" showDetail="true" />
<p:commandButton type="button" onclick="rcName([{name:'model', value:'Buick Encore'}, {name:'year', value:2015}]);" value="Pass Parameters 1" /><br/>
<p:commandButton type="button" onclick="clicked();" value="Pass Parameters 2" />
</h:form>
<script type="text/javascript">
//<![CDATA[
function clicked(){
rcName([{name:'model', value: 'Chevy Volt'}, {name:'year', value:2016}]);
}
//]]>
</script>
@ManagedBean
public class RemoteCommandView {
public void beanMethod() {
// OR - retrieve values inside beanMethod
String model1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("model");
String year1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("year");
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Executed",
"Using RemoteCommand with parameters model := " + model + ", year := " + year));
}
@ManagedProperty("#{param.model}")
private String model;
@ManagedProperty("#{param.year}")
private int year;
public void setModel(String model) {
this.model = model; // value set by JSF
}
public void setYear(int year) {
this.year = year;
}
}
David F. Suárez Chacón
Points
69