How can I make <p:commandLink>
without submit? Just for JS execution.
For <p:commandButton>
I can do it this way:
<p:commandButton value="JS button" type="button" onclick="alert('clicked')"/>
What is the analog for <p:commandLink>
?
Just return false
from the JavaScript handler.
<p:commandLink ... onclick="alert('clicked'); return false;" />
The same applies to all other on*
attributes and the command button, by the way.
<p:commandButton ... onclick="alert('clicked'); return false;" />
Whenever you return false
from any JavaScript on*
attribute on a HTML element, the element's default action/behavior (in this case, submitting the form) will be blocked.
Nonetheless, if you don't need to invoke a JSF backing bean action method after all, just don't use a command link/button component in first place. Use a plain link/button component.
<h:link ... onclick="alert('clicked'); return false;" />
<p:button ... onclick="alert('clicked'); return false;" />
Those doesn't need to be placed in a form, too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With