And how about storing the value to a session or a cookie from javascript and reading from java server through an implemantation of observer parttern? It would work in any case, in any framework.
Στις Τετ, 29 Αυγ 2018, 2:39 μ.μ. ο χρήστης marwa hussein < marwa.huss...@gmail.com> έγραψε: > Hi, > Thank you all for guiding me to the solution especially "Numa" .. and this > is how I solved it: > for the .tml > <p id="myId" data-mydata="testvalue"/> > > and in the JS JQuery file, I passed the variable in a JSON object --> data: > {myData:dataToSend} > $('#myId').click(function() { > var dataToSend= $('#myId').data('mydata'); > ajax('answer', { > element: $('#myId'), > data:{ myData:dataToSend}, > success: function(response) { > } > }); > }); > > and in java file, I used @RequestParameter("myData") to get the value from > the JSON object: > @OnEvent("answer") > @PublishEvent > public void answer(@RequestParameter("myData") String varName) > { > System.out.println("Variable name is :"+ varName ); > } > > Regards, > Marwa > > > On Tue, Aug 28, 2018 at 3:20 PM Numa Schmeder <n...@dfacto.ch> wrote: > > > Hello Marwa, > > > > The answer provided by Thiago is much simpler. > > Just put your data in a data attribute of a tag and then use the tutorial > > ajax and zones to send this data to a server side event handler. > > If you want to do it automatically without triggering a javascript event, > > just put you script in an on document ready event, to make sure your > > javascript code is called once the page is rendered and loaded by the > > browser. > > > > > > ===> in html page > > > > <div id=“myId” data-mydata=“mydata"></div> > > > > ===> javascript at the end of html page > > > > $(function() { > > var dataToSend = $(‘#myId’).data(‘mydata’); > > ajax(‘pageData', { > > data: dataToSend, // This doesn't need to be the > > same element as the one two lines above > > // Callback called when the request is finished. > > // response.json is the object returned by the event handler > > method > > success: function(response) { > > alert('sent to server'); > > } > > }); > > }); > > > > > > =====> in java page > > > > JSONObject onPageData() > > { > > return new JSONObject("origin", "componentAction"); > > } > > > > > > You can use jquery or something else. > > > > Best > > Numa > > > > > > > > <http://www.dfacto.ch/> Numa Schmeder www.dfacto.ch < > > http://www.dfacto.ch/> > > n...@dfacto.ch <mailto:n...@dfacto.ch> | M +41 79 538 30 01 > > > > DIGITAL STRATEGY | DESIGN | DEVELOPMENT > > > > > > > > > > > Le 28 août 2018 à 12:22, marwa hussein <marwa.huss...@gmail.com> a > > écrit : > > > > > > Hello, > > > > > > Thanks all for your suggestions. I followed the example shown in > > > https://tapestry.apache.org/ajax-and-zones.html in "Invoking > server-side > > > event handler methods from JavaScript" but here the event is in the > > java > > > code "server-side" and is invoked from the Javascript code "onClick()" > , > > > but what I want is the opposite direction, sending a "string variable" > > from > > > a tag appended in the clientside javascript code to the java code "in > > the > > > serverside". > > > For now, I will test to use hidden input (although I didn't want to > use a > > > form submit) and I will see if I can make it or not ... > > > > > > Thank you all for your help and valuable suggestions, and of course, if > > > anyone face the same problem before and could give me hints to how to > do > > it > > > please tell me. > > > Regards, > > > Marwa > > > > > > -- > > > > *Marwa Hussein M. TA @ Information Systems Department Faculty of Computers > & Information Assuit University* > <imanhe...@yahoo.com> >