views:

16

answers:

1

I have richfaces application. In the page, there is jQuery function defined:

<rich:jQuery timing="onJScall" name="updateUrlHash" selector="#conversationId" 
    query="alert('in jquery call');" />

Then I have some a4j:commandLink, which should call the function on completing ajax request.

<a4j:commandLink value="test" oncomplete="updateUrlHash(this)" />

Unfortunately, it does not work. I know oncomplete works, because if I put there alert('test');, alert is shown. But when I try to call updateUrlHash function, it does not work. I checked in page source that function is there. What can be wrong?

+1  A: 

I found it. Query is called on object selected by jQuery selector. So in example like this, in javascript is it

jQuery(selector).alert('in jquery call');

This of course cannot work. So I need to call anything on selected element, and then I can do what I want:

query="hide(); alert('this works');"

In Javascript it is then (selected element is hidden anyway):

jQuery(selector).hide(); alert('this works');
amorfis
Interesting. But can't you just define it as a plain vanilla JS function instead of using `rich:jQuery`?
BalusC
I could, but I wanted to use plain JSF id (#conversationId), which in generated page is like `blabla:formbla:conversationId'. <rich:jQuery> handles it for me. And it was interesting problem anyway :)
amorfis
Ah, it works that way. Thanks for sharing.
BalusC