You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Sanket Sharma <sa...@gmail.com> on 2014/06/20 23:03:12 UTC

AJAX and Mixin events

Hi,

I am trying to create a mixin for geocoding user input and  displaying it
on a map.

As suggested in previous questions in the forum, I implemented a mixin.

In my template (listing/AddListing.tml) I have:

<t:textfield t:id="addressLineOne" t:mixins="OpenStreetMaps"/>

In my component class, I have:

Object onGeocodeAddressFromAddressLineOne(String input) {
// Need to return JSON here
logger.debug("********* returning JSON data******");
logger.debug("*********Input recevied as*********" + input);
return null;
}

and in my mixin class I have:

private static final String GEOCODE_REQUEST_EVENT = "geocodeAddress";
Link eventLink = resources.createEventLink(GEOCODE_REQUEST_EVENT);

And there is some javascript that waits for "change" event on the text
fields and fires an AJAX request.
Now, everything seems to be working - when I enter text in the field, It
triggers the AJAX request.
However, the AJAX request fails with HTTP 500 (internal server error) and I
picked up following the logs:

[ERROR] TapestryModule.RequestExceptionHandler Processing of request failed
with uncaught exception:
org.apache.tapestry5.ioc.internal.OperationException: Request event
'geocodeaddress' (on component listing/Add:addresslineone) was not handled;
you must provide a matching event handler method in the component or in one
of its containers. [at
classpath:com/dukstra/travelnet/web/pages/listing/AddListing.tml, line 31]
org.apache.tapestry5.ioc.internal.OperationException: Request event
'geocodeaddress' (on component listing/Add:addresslineone) was not handled;
you must provide a matching event handler method in the component or in one
of its containers. [at
classpath:com/dukstra/travelnet/web/pages/listing/AddListing.tml, line 31]

I tried adding the @OnEvent(value="geocodeaddress" and
component="addressLineOne") to the event handle above, but its still
failing.

Can't seem to figure out whats wrong? Would appreciate any help.

Best Regards,
Sanket

Re: AJAX and Mixin events

Posted by Sanket Sharma <sa...@gmail.com>.
BTW, digging into code and API docs, I read:

boolean
org.apache.tapestry5.runtime.Component.dispatchComponentEvent(ComponentEvent
event)

Invoked to handle a component event. Methods with the OnEvent annotation
(or the matching naming convention) will be invoked until one returns a
non-null value.

So I updated to code above to return a JSON object instead of null. But
still throwing the same error.




On Fri, Jun 20, 2014 at 11:03 PM, Sanket Sharma <sa...@gmail.com>
wrote:

> Hi,
>
> I am trying to create a mixin for geocoding user input and  displaying it
> on a map.
>
> As suggested in previous questions in the forum, I implemented a mixin.
>
> In my template (listing/AddListing.tml) I have:
>
> <t:textfield t:id="addressLineOne" t:mixins="OpenStreetMaps"/>
>
> In my component class, I have:
>
> Object onGeocodeAddressFromAddressLineOne(String input) {
> // Need to return JSON here
>  logger.debug("********* returning JSON data******");
> logger.debug("*********Input recevied as*********" + input);
>  return null;
> }
>
> and in my mixin class I have:
>
> private static final String GEOCODE_REQUEST_EVENT = "geocodeAddress";
> Link eventLink = resources.createEventLink(GEOCODE_REQUEST_EVENT);
>
> And there is some javascript that waits for "change" event on the text
> fields and fires an AJAX request.
> Now, everything seems to be working - when I enter text in the field, It
> triggers the AJAX request.
> However, the AJAX request fails with HTTP 500 (internal server error) and
> I picked up following the logs:
>
> [ERROR] TapestryModule.RequestExceptionHandler Processing of request
> failed with uncaught exception:
> org.apache.tapestry5.ioc.internal.OperationException: Request event
> 'geocodeaddress' (on component listing/Add:addresslineone) was not handled;
> you must provide a matching event handler method in the component or in one
> of its containers. [at
> classpath:com/dukstra/travelnet/web/pages/listing/AddListing.tml, line 31]
> org.apache.tapestry5.ioc.internal.OperationException: Request event
> 'geocodeaddress' (on component listing/Add:addresslineone) was not handled;
> you must provide a matching event handler method in the component or in one
> of its containers. [at
> classpath:com/dukstra/travelnet/web/pages/listing/AddListing.tml, line 31]
>
> I tried adding the @OnEvent(value="geocodeaddress" and
> component="addressLineOne") to the event handle above, but its still
> failing.
>
> Can't seem to figure out whats wrong? Would appreciate any help.
>
> Best Regards,
> Sanket
>
>
>
>
>
>

Re: AJAX and Mixin events

Posted by Sanket Sharma <sa...@gmail.com>.
*Bah*...mustn't work late on Friday nights!!

Thanks for help.

Best Regards,
Sanket


On Sat, Jun 21, 2014 at 12:30 AM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Fri, 20 Jun 2014 18:03:12 -0300, Sanket Sharma <sa...@gmail.com>
> wrote:
>
>  Hi,
>>
>
> Hi!
>
>  <t:textfield t:id="addressLineOne" t:mixins="OpenStreetMaps"/>
>>
>> In my component class, I have:
>>
>> Object onGeocodeAddressFromAddressLineOne(String input) {
>> // Need to return JSON here
>> logger.debug("********* returning JSON data******");
>> logger.debug("*********Input recevied as*********" + input);
>> return null;
>> }
>>
>> and in my mixin class I have:
>>
>> private static final String GEOCODE_REQUEST_EVENT = "geocodeAddress";
>> Link eventLink = resources.createEventLink(GEOCODE_REQUEST_EVENT);
>>
>
> You created the event link without a context and our event handler method
> has a context (the input parameter). That's why the event wasn't handled:
> the method has more event context values (parameters) (one) then the
> request (zero). Remove the parameter, pass anything you want from JS to
> class through query parameters and it'll work.
>
> This isn't related to AJAX or mixins at all.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: AJAX and Mixin events

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 20 Jun 2014 18:03:12 -0300, Sanket Sharma <sa...@gmail.com>  
wrote:

> Hi,

Hi!

> <t:textfield t:id="addressLineOne" t:mixins="OpenStreetMaps"/>
>
> In my component class, I have:
>
> Object onGeocodeAddressFromAddressLineOne(String input) {
> // Need to return JSON here
> logger.debug("********* returning JSON data******");
> logger.debug("*********Input recevied as*********" + input);
> return null;
> }
>
> and in my mixin class I have:
>
> private static final String GEOCODE_REQUEST_EVENT = "geocodeAddress";
> Link eventLink = resources.createEventLink(GEOCODE_REQUEST_EVENT);

You created the event link without a context and our event handler method  
has a context (the input parameter). That's why the event wasn't handled:  
the method has more event context values (parameters) (one) then the  
request (zero). Remove the parameter, pass anything you want from JS to  
class through query parameters and it'll work.

This isn't related to AJAX or mixins at all.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org