jsf - <f:ajax listener="#{bean.selectPlan}" call to @PostConstruct before execute the selectPlan method -
this question has answer here:
i have check box
in application , want call selectplan method execute when user select check box
but when ever select check box
call @postconstruct
method before selectplan method.
this leads unwanted calls end have written functions populate data when page load in @postconstruct
<td> <h:selectbooleancheckbox value="#{plan.checked}"> <f:ajax listener="#{planoverlay.selectplan}" render=":overlayform:mytable"/> </h:selectbooleancheckbox> </td>
below bean class
import javax.faces.bean.managedbean; import javax.faces.bean.viewscoped; @managedbean(name = "planoverlay") @viewscoped public class planoverlaybean extends overlaybean { @postconstruct public void init() { super.init(); loadplansfrom_db(); } public void selectplan(ajaxbehaviorevent event) throws exception { getoverlay().getservice().setselectedplan(rowdata); } }
to avoid case,we should check if postback or ajaxrequest. if bean viewscoped,you can add below code post-construct method.
maybe not best case works.
also can use jsf 2 prerenderviewevent initialization bean.
if (!facescontext.getcurrentinstance().ispostback()) { if (!facescontext.getcurrentinstance().getpartialviewcontext().isajaxrequest()) { //some initialization } }
Comments
Post a Comment