Call Java Method From JavaScript Function

hi everyone

i need a help in calling Java method from a javaScript method

ex:

function confirmAddRecord() {

cHours =document.getElementById('frmP:ChargeHours').value;

cSTime =document.getElementById('frmP:ChargeStartTime').value;

var answer = confirm("Are you sure you want to add Record?")

if (answer){

here i want to call the Java Method that is located in session bean that takes the upper params cHours & cSTime

}

else{

return false;

}

}

i know i can do it as an action button but it is required me to be in that way can any one help plz

Message was edited by:

casper77

[696 byte] By [casper77a] at [2007-11-26 23:49:26]
# 1
XMLHttpRequest?Vu
vuqphama at 2007-7-11 15:26:03 > top of Java-index,Development Tools,Java Tools...
# 2

I think what you mean is some kind of client validation. You may use a normal JSF button action (of course invoked on server side) and set the onClick attribute to

"confirmAddRecord()".

Perhaps you ask how to invoke a "normal JSF button action". Then you have to include JSF components in your JSP instead of plain HTML.

Ingmara at 2007-7-11 15:26:03 > top of Java-index,Development Tools,Java Tools...
# 3

so you want to do AJAX huh?

The sun JSF blueprint components do what you want (check the java and jaavascript source code for the Autocomplete component).

I copied their method which uses dojo and shale remoting.

It becomes kludgy as soon as you use tables however.... hopefully ajax will be better integrated in the future.

thepigs2a at 2007-7-11 15:26:03 > top of Java-index,Development Tools,Java Tools...
# 4

thanks guys

but the problem is how to call a Java Method From JavaScript Function

and i don't need Ajax thanks thepigs

ingmar iam calling this function when i onclick a button it is true

but in javaScript Code how could i call Java Method with params

thanks All

casper77a at 2007-7-11 15:26:03 > top of Java-index,Development Tools,Java Tools...
# 5

That depends on the nature of your parameters. I guess you calculate the params on client and then want to submit them. In this case and if you don't want to use Ajax simple add some <input type="hidden"> elements (of course there correspondend components dependent of your framework) and store the params there. If the javascript isn't invoked by a button click, you can use a button nevertheless. Set visible="false" and call

document.getElementById('client_id_of_my_hidden_button').click();

(or maybe doClick() dependent on your framework).

Ingmara at 2007-7-11 15:26:03 > top of Java-index,Development Tools,Java Tools...
# 6
thanks a lot Ingmar it worked by putting a hidden button thanks again
casper77a at 2007-7-11 15:26:03 > top of Java-index,Development Tools,Java Tools...