• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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  :)
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic