This question has been asked before. The action is used when you want to call a method in your bean support. eg
action="#{myBean.myMethod}"
The code for bean will be similar to
@ManagedBean(name = "myBean", eager = true) @ViewScoped public class MyBean{ myMethod(){ // your method code here } }
As always, the action listener does the same, except that it fires with an event
myMethod(Event e){ // your method code here }
Please note that the event can be of any type.
onclick works before sending an ajax request. I donβt know much. I just used it for user interface purposes, for example, closing the dialog when I click
<p:commandButton id="cancel" value="Cancel" icon="ui-icon ui-icon-arrowreturnthick-1-w" style="float:right;" onclick="PF("dlg").hide()" type="button"> </p:commandButton>
SEE ALSO
Differences between action and actionListener
Anas
source share