jsf 2 - How do I add ajax behavior to a dynamically created component in a backing bean? -
in respose infragile's request in thread, asking separate question rather followup.
here problem attempting address: i'm migrating jsf1.2 jsf2. worked fine in jsf1.2. have rewritten critical item composite component panel created in backing bean adding components in code.
in particular, have h:inputtext , h:selectonemenu components create in code along "apply" h:commandbutton. "apply" button has action listener checks values in h:inputtext , h:selectonemenu components. works fine, when fetch values in h:inputtext or h:selectonemenu components original values, not new values entered user. said, worked fine in jsf1.2 (i got new values), not in jsf2 reason.
i have tried several things around haven't worked, figured add ajax behavior h:inputtext , h:selectonemenu items , when values in these components change, call backing bean listener ajax behavior fetch new values.
i trying add ajax behavior component create in code (not bound page component). can create component no problem. however, problem having how add ajax behavior component.
could post sample code add ajax behavior value change or blur event? here code use create component in code - how need modify add ajax behavior? hpg = new htmlpanelgrid(); children = hpg.getchildren(); children.clear(); .... input = new htmlinputtext(); .... children.add(input);
what code have add replace "add ajax behavior here" line, , arguement listener method (arguement method replace ????? below)?
public void myajaxlistener(?????) { ...... {
i have been trying handle on time now. feel pretty close, don't know syntax need. can provide more information on how fetching component ids , searching values in action listener if help.
thanks
this how can add dynamically ajaxbehaviorlistener yor component:
... htmlinputtext inputext = new htmlinputtext(); ajaxbehavior blurbehavior = new ajaxbehavior(); blurbehavior.addajaxbehaviorlistener(new blurlistener()); blurbehavior.settransient(true); inputtext.addclientbehavior("blur", blurbehavior) ... public class blurlistener implements ajaxbehaviorlistener { public blurlistener() { } @override public void processajaxbehavior(ajaxbehaviorevent event) { // job htmlinputtext inputtext = event.getcomponent(); // input text component ... } }
"blur" represents event when listener triggered. remember jsf component must support event, otherwise won't work.
(here can see under covers , how build custom ajax component http://weblogs.java.net/blog/driscoll/archive/2009/10/09/jsf-2-custom-java-components-and-ajax-behaviors?force=670 )
however in case think problem buttons actionlistener triggered before actual component values submited. can solve moving actionlistener logic button action, aformentioned ajax, maybe findinng actual values in uicomponents (htmlinputtext, uiselectone), not sure immediate attribute can influence it.
Comments
Post a Comment