On 16/12/2012, at 10:14 AM, Muhammad Gelbana wrote:

> Some tapestry components do fire ajax events and reach out to the server
> and it get's handy sometimes to listen to those events. For instance the
> datefield event fired to format the selected date. Side question, why does
> the date field have to reach out to the server to format the selected date,
> can't it be done on the client side ?

From the source code of the DateField component, here is the "Format" event 
handler:

    /**
     * Ajax event handler, used after the client-side popup completes. The 
client sends the date, formatted as
     * milliseconds since the epoch, to the server, which reformats it 
according to the server side format and returns
     * the result.
     */
    JSONObject onFormat(@RequestParameter(INPUT_PARAMETER)
                        String input)
    {
        JSONObject response = new JSONObject();

        try
        {
            long millis = Long.parseLong(input);

            Date date = new Date(millis);

            response.put(RESULT, format.format(date));
        } catch (NumberFormatException ex)
        {
            response.put(ERROR, ex.getMessage());
        }

        return response;
    }

> 
> Any way the main question is, I saw this url being posted using ajax:
> 
>> http://localhost/tests/results.starttime:format?input=1351232300000
> 
> 
> So I tried listening to the "format" event fired from the "starttime"
> component but I got nothing. I thought may be it's the missing context so i
> added a "long" parameter to the even method, but it didn't work either.
> 
> So how I can I, on the server side, listen to the datefield component fired
> ajax events ? And how can this be done in general since some urls indicate
> events that aren't actually the events being listened to on the server !

You can't.  As you can see in the source above, DateField handles "Format" 
without bubbling up an event to the container. If you need bubbling up, then 
try creating your your component by subclassing DateField and overriding the 
above method.

> Like the zone refreshing mixin. It fires a "zonerefresh" event while I
> could listen to it only through the "refresh" event.

From the source code of the "ZoneRefresh" component, here is the "ZoneRefresh" 
event handler:

   Object onZoneRefresh()
   {
      CaptureResultCallback<Object> callback = new 
CaptureResultCallback<Object>();
      resources.triggerEvent(EventConstants.REFRESH, context, callback);
      
      if(callback.getResult() != null){
         return callback.getResult();
      }
      
      return zone.getBody();
   }

As you can see, it bubbles up the REFRESH event.

This may help:

        http://localhost:8080/jumpstart/examples/component/eventbubbling

> 
> Thank you.

Cheers,
Geoff

Reply via email to