Hi everyone!
Is it possible to call a Bean-Method with Parameters using JavaScript?
A way to transfer the String-Parameter to a Member-Variable of the Bean and then call the method would also be ok...
thank for your help!
Bernd
Calling Bean-Method with Parameters from JavaScript
Hello,
Yes, there is a way. Look p:remoteCommand please. It has "process", "update", "actionListener", "action" attributes and is called by JavaScript. With "process" you can transfer parametes to managed bean, then execute your logic in action / actionListener and have subsequent update at the end. I use that in my web app and it works fine. I set e.g. some values in h:hiddenField (client-side by JS) and point to this field in "process" attribute of p:remoteCommand.
Best regards.
Yes, there is a way. Look p:remoteCommand please. It has "process", "update", "actionListener", "action" attributes and is called by JavaScript. With "process" you can transfer parametes to managed bean, then execute your logic in action / actionListener and have subsequent update at the end. I use that in my web app and it works fine. I set e.g. some values in h:hiddenField (client-side by JS) and point to this field in "process" attribute of p:remoteCommand.
Best regards.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
Yes. I haveHeety wrote:so the first step in the p:remoteCommand is to do the process-attribute, the second one is to do the action-listener and the third is to update everything you want?
thanks for your help, i'll try it out an report if it worked out.
Code: Select all
<h:inputHidden id="infoForProps" value="#{newSocBean.infoForProp}"/>
..................
<p:remoteCommand name="rcShowMorePropsInfo" process="@this,infoForProps" update="dataTableMorePropInfos"
actionListener="#{newSocBean.buildInfoProperties}" oncomplete="showMorePropInfosTable('#{newSocBean.sidebarSelection}')"/>
Code: Select all
function showMorePropsInfo(listTyp, hiddenFieldId)
{
var selectedOptions;
if (listTyp == 'source') {
selectedOptions = pickListPropsWidget.selectedSource();
} else if (listTyp == 'target') {
selectedOptions = pickListPropsWidget.selectedTarget();
} else {
alert("Undefined list type");
}
jQuery("#" + hiddenFieldId).val(selectedOptions.join(";"));
rcShowMorePropsInfo();
}
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
thanks for the example...
i've builded somethink similar to yours, but it looks like the action/actionlistener method is never executed...
my bean:
jsf:
and finally the js call:
the 2 alerts at onstart and oncomplete work, but the actionmethod is never executed...
any idea why this didn't work out?
i've builded somethink similar to yours, but it looks like the action/actionlistener method is never executed...
my bean:
Code: Select all
public class Karte {
private String mapOpp;
...
public String mapOperation() {
System.out.println(this.mapOpp);
String[] werte = this.mapOpp.split(":");
if (werte[0].equals("Drag")) {
String[] xyKoords = werte[1].split(";");
KarteDao.getInstance().moveMapXY(this, Double.parseDouble(xyKoords[0]), Double.parseDouble(xyKoords[1]));
}
if (werte[0].equals("slider")) {
KarteDao.getInstance().zoomMap(this, Double.parseDouble(werte[1]));
}
if (werte[0].equals("wheel")) {
werte = werte[1].split(";");
KarteDao.getInstance().zoomMapWheel(this, Double.parseDouble(werte[0]), Double.parseDouble(werte[1]), Double.parseDouble(werte[2]));
}
return "";
}
}
Code: Select all
<h:form id="myForm">
<h:inputHidden id="myFormIH" value="#{SessionBean.karte.mapOpp}"></h:inputHidden>
<p:remoteCommand onstart="alert('start');" oncomplete="alert('complete');" name="myFormRC" actionListener="#{SessionBean.karte.mapOperation}" process="@all"></p:remoteCommand>
</h:form>
Code: Select all
function moveMapRight()
{
mapSrc=document.getElementById("map").src;
document.getElementById("myForm:myFormIH").value="Drag:70;0";
//document.forms["myForm"].submit();
myFormRC();
waitForLoad();
}
any idea why this didn't work out?
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Try;
In JSF 2, actionevent is optional parameter.
Code: Select all
public void mapOperation(ActionEvent ae) {
-
- Information
-
Who is online
Users browsing this forum: No registered users and 37 guests