Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I pass a javascript value as a parameter to a Java method?  RSS feed

 
Stavros Vrakas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I am relatively new in using Primefaces and I have created UI, which I feed with data which I get
from my database.

I have created a java service (MyArticlesService) and I have programmed a method which gets the id of
a div in order to get the data from the database.

In the onclick event of my div I make the call to the method (getSelectedProduct) which
exists in my service (MyArticlesService) and I try to pass the id of the div which was clicked, by
using javascript (this.id). See code excerpt below:


in onclick event:


I make a java call to the method getSelectedProduct and I try to pass the "this.id" javascript value as
parameter.

I face though the following problem:

javascript in not recognized as javascript but it is manipulated as Java code.

The question is:

How can I pass a javascript value/parameter as a parameter to a Java method?

In case you have any ideas or an answer, I would really appreciate your feedback.

Thank you in advance  :)
 
Dave Tolls
Ranch Hand
Posts: 2504
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Javascript exists on the client.
The Java code exists only on the server.

The only way to get Javascript values to the Java code is to submit them to the server.
 
Mike London
Ranch Hand
Posts: 1338
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:The Javascript exists on the client.
The Java code exists only on the server.

The only way to get Javascript values to the Java code is to submit them to the server.


Just to clarify, I think you mean Submit as in an HTML Form "Submit".

Not sure that was clear for the OP.

- mike
 
Stavros Vrakas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

you can find the answer here, or you can follow this link: http://forum.primefaces.org/viewtopic.php?f=3&t=46244


the solution is to use pe:remoteCommand element. pe:remoteCommand is an extension of primefaces and in order
in order to use it, I added:



in my element, so that I can use the

I have found a very good example in this URL: http://www.primefaces.org/showcase-ext/sections/remoteCommand/methodParam.jsf;jsessionid=13qynorr7lp2x1guaz2s2nbifd
and I changed the code so that the onclick event happens on the div and I did not use the <p:commandButton>, which is used in the example I found in
link above.

The final code looks like this:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!