You can also handle POST events by injecting the request: @Inject private Request request;
And then responding the the event (in my case, "generateJSON"): JSONObject onGenerateJSON() { int displayLength = Integer.valueOf(request.getParameter("iDisplayLength")); int displayStart = Integer.valueOf(request.getParameter("iDisplayStart")); ... } mrg On Thu, Dec 9, 2010 at 6:47 AM, Richard Hill <r...@su3analytics.com> wrote: > > If you want to make an ajax call from your own javascript you can do the > following (T5.1). In this example we just stick the value you want to > cache in an @Persist'd field. > > In your page/component .java: > > @Persist > private String valueToStore; > > public StreamResponse onYourEventName(String valueToStore) { > this.valueToStore = valueToStore; > return new StreamResponse("text", valueToStore + " was persisted"; > } > > Now your javascript just needs to make a normal ajax GET request to: > > /yourpage:youreventname/valueToStore > > which in this case will (hopefully) just return the confirmation > message. You can also use JSONObject to construct json arrays to return > as well if you want to update any data on your page. > > You can use ComponentResources to create event links too which can be > added to your .tml and read by javascript if you wish: > > public String getMyEventLink() { > String context = ...; > Link l = componentResources.createEventLink("YourEvent", context); > return l.toString(); > } > > ... ${myEventLink} ... > > Hope that helps, > > Richard. > > > > -----Original Message----- > From: Thiago H. de Paula Figueiredo <thiag...@gmail.com> > Reply-to: "Tapestry users" <users@tapestry.apache.org> > To: Tapestry users <users@tapestry.apache.org> > Subject: Re: Calling the Tapestry server from plain Javascript > Date: Wed, 08 Dec 2010 21:07:51 -0200 > > On Wed, 08 Dec 2010 20:55:27 -0200, Tim Koop <t...@timkoop.com> wrote: > >> I have a pile of Javascript on my page (it's a component really), and >> sometimes it comes up with a value it needs to store on the server (in a >> SessionState or something). Can someone please tell me the best way to >> call the server from plain Javascript? > > Create an event and pass its URL (created from > ComponentResources.createEventLink()) to your JavaScript code. Create a > event handler method for it. Request it using normal AJAX code from the > JavaScript side. If you need to return JSON, just return an JSONObject or > JSONArray instance in the event handler method. This works for pages, > componentes and mixins in the same way. > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org