I have googled it several times but i can't get a solution. I want to make javascript function call from the bean class in jsf and i get that using the following code.
RequestContext.getCurrentInstance().execute("handleResize()");
and is workign fine. But I want to give two parameters to that function height and width. How can it be done ? please help
I have googled it several times but i can't get a solution. I want to make javascript function call from the bean class in jsf and i get that using the following code.
RequestContext.getCurrentInstance().execute("handleResize()");
and is workign fine. But I want to give two parameters to that function height and width. How can it be done ? please help
-
Maybe
RequestContext.getCurrentInstance().execute("handleResize(100, 200)");
? – Thilo Commented Sep 12, 2013 at 6:41 - Not static values. I tried with static values and it work. But i want to pass dynamic values. – Nikhil Commented Sep 12, 2013 at 6:49
- @nik Give us an example. – Rong Nguyen Commented Sep 12, 2013 at 7:28
- @RongNK like int h=500,w=300; RequestContext.getCurrentInstance().execute("handleResize(h, w)"); – Nikhil Commented Sep 12, 2013 at 8:56
-
@nik
String str = "handleResize(" + h + "," + w + ")"
, and thenRequestContext.getCurrentInstance().execute(str)
– Rong Nguyen Commented Sep 12, 2013 at 8:58
1 Answer
Reset to default 5You seem to fail to grasp the fact that in the context of Java/JSF, all the HTML, CSS and JavaScript code are merely plain vanilla String
s and you seem to expect that HTML/CSS/JS somehow magically runs inside Java/JSF code. This is not true. Java/JSF is a HTML/CSS/JS code producer, not executor. The webbrowser retrieves them all as one big String
and then parses and executes it.
If you want to invoke a JS function with parameters supplied, like so when you would do in real JS code:
handleResize(500, 300);
And you have those values as Java variables, then you just need to make sure that you write Java code in such way that exactly the above String
is produced (again, this is just Java code, no JS code):
String call = "handleResize(" + w + ", " + h + ")";
You can verify beforehand by printing it to the stdout/logger:
System.out.println(call);
It must print exactly the desired valid JS function call syntax handleResize(500, 300);
.
If it does, then just pass that unmodified to RequestContext#execute()
.
RequestContext.getCurrentInstance().execute(call);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745041427a4607829.html
评论列表(0条)