PDA

View Full Version : Dynamic link/action creation by javascript



fritzrichter
Jul 30th, 2010, 07:12 AM
Hi guys,
I was looking for a solution for my topic a while and was not able to find any hints. In order to use some javascript components (f.e. a contextMenu) I need to create links/actions dynamicly by javascript (runtime in browser).

Here is an example for what I need this feature:
I have a datatable with different objects (and their ids). No I want to provide a contextMenu (with jquery, or whatever). When I click on an item, the generic contextMenu pops up and I can select an entry. By clicking an item in the menu, a javascript method is called. In this called method, I need to invoke an action with parameters in a dynamicly way. For example I would like to read the id of a selected object, put this id as a parameter to my url which I want to invoke.

As far as I have seen, there is no way to create links on demand. I have seen the a4j-javascript tag, which will create js-methods, which I can invoke. But this will mean, that I must add (f.e. for 100 items in my table), 100 aj4 tags = 100 js methods are created. Is there no way where I only have ONE method, which will add some parameters (f.e. ?itemId=33) and than invoke the link?

I ask, because the html output is sometimes so large, that the entire page will get really slow and ugly to read.

Thanks for your answers.

P.S. Is there any way, to make use of jQuery instead of the jsf js, spring dojo, richfaces, and all these ugly js-frameworks?