jsf - Primefaces how to fire another event after datatable select event -


i have datatable selection , commandbutton. problem if user doesn't select item datatable , clicks button, selecteditem object returns null. think datatable's selection event runs after commandbutton's action method.

what want is; if user doesn't select item datatable , clicks button, create new selecteditem object. after button's action method runs, datatable changes null.

<p:panel id="panel1"> <p:datatable selection="#{mycontroller.selecteditem}"              selectionmode="single".... //some other stuff </p:panel>  <p:panel id="panel2"> //some other stuff <p:commandbutton value="create" action="mycontroller.create".... </p:panel> 

my controller;

selecteditem selecteditem = new selecteditem();  public void create(){  selecteditem = new selecteditem(); } 

you can try this:
.xhtml

<p:datatable var="result" selection="#{mycontroller.selecteditem}"          selectionmode="single"....  <p:commandbutton actionlistener="#{mycontroller.create()}">     <f:setpropertyactionlistener value="#{result}" target="#{mycontroller.selecteditem}" />   </p:commandbutton>       

.java

selecteditem selecteditem = new selecteditem();    public void create(){   selecteditem = new selecteditem(); } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -