You need to sign in to do that
Don't have an account?

apex:actionsupport onclick event is not working
Hi,
I want to call an apex method from outputilnk.
so, i tried using below code in VF page:
<apex:outputLink value="/{!p.Id}" onclick="CallApexMethod"> {!p.Name} </apex:outputLink>
<apex:actionFunction name="CallApexMethod" action="{!policy5}" onComplete="alert('After apex method') ;"/>
In class:
public PageReference policy5() {
Update ListPolicy;
return null;
}
When I click on the output link , it should actually go to the record detail page.
So, with the above code when I click the link in the same browser Tab then it is working as expected like it is calling apex method and also redirecting to the record detail page.
but if I click on the link to open in new Tab, the above code is not working and its not executing my apex method.
IS there any other way to achieve the functionality i.e. both the ways (in the same tab as well in the new tab)?
Use like this
<apex:outputLink value="your URL" target="_blank">Edit</apex:outputLink>
Thanks and regards,
Subra.J
Trinay Technology Solutions
Hi,
Thanks for the reply.
I already tried it but of no use, when I click on that link directly then its working.
but if I right click on that link and if I select "Open in new window or Open in new Tab" then its not working.
Try using a commandlink instead of an outputlink, then you can put your method call directly into the link instead of having to use actionFunctions:
<apex:commandLink value="{!p.Name}" action="{!policy5}" oncomplete="alert('After apex method');"/>
And update your policy5 method to return a PageReference, and return your link that way (ie return "/{!p.Id}" in your policy5 method)
Actually, if you wanted to stick to your current way of doing things then there might be a couple of things causing it not to work.
Try changing this
to this
Note the (); after your function call. You have to treat the onclick event like a normal javascript function call, so adding the (); after CallApexMethod should help.
Now, in your action function, change onComplete to oncomplete - event names are case sensitive and I've encountered problems before with events not firing because of case sensitivity.
That should help, having said all that, I'd still go with my original solution because it doesn't require script and so should be more compatible.