java - f:ValueChangeListener nullifying EJB injection -



java - f:ValueChangeListener nullifying EJB injection -

it loads statelist fine, when alter value of state, calls backbean addressbo null. how can prepare it? other way it?

thanks in advance.

<h:selectonemenu id="statelist" value="#{newusercontroller.address.stateid}"> <f:selectitems value="#{addresscontroller.statelist}" /> <f:valuechangelistener type="controller.address.addresscontroller"/> <f:ajax event="change" render="cidadelist"/> </h:selectonemenu> <h:selectonemenu id="citylist" value="#{newusercontroller.address.cityid}"> <f:selectitems value="#{addresscontroller.citylist}" /> </h:selectonemenu>

backbean

package controller.address; @managedbean @requestscoped public class addresscontroller implements valuechangelistener { @ejb private addressbo addressbo; @postconstruct public void firstthingtodo() { statelist = enderecobo.loadstatelistselectitem(); } @override public void processvaluechange(valuechangeevent event) throws abortprocessingexception { string state = (string) event.getnewvalue(); citylist = addressbo.loadcitylist(state); } }

the other backbean set's value of address , user not appearing in case.

package controller.user; @managedbean @requestscoped public class newusercontroller { private address address; private user user; @ejb private newuserbo newuserbo; public void registernewuser() { newuserbo.register(user, address); } public address getaddress() { homecoming this.address; } public void setaddress(address address) { this.address = address; } public user getuser() { homecoming this.user; } public void setuser(user user) { this.user = user; } }

the first problem you're creating brand new instance of class in <f:valuechangelistener> tag. not same instance referenced @managedbean , managed bean related annotations won't invoked on well. rather utilize valuechangelistener="#{addresscontroller.processvaluechange}" on <h:selectonemenu> instead. doesn't solve everything. alter big sec list don't behave expected.

the sec problem value alter listener method invoked during validations phase. wrong moment change/load model values. should during invoke action phase. utilize listener attribute of <f:ajax>.

so:

class="lang-xml prettyprint-override"><h:selectonemenu id="statelist" value="#{newusercontroller.address.stateid}"> <f:selectitems value="#{addresscontroller.statelist}" /> <f:ajax listener="#{addresscontroller.changestate}" render="cidadelist" /> </h:selectonemenu>

with

@managedbean @requestscoped public class addresscontroller { @ejb private addressbo addressbo; @postconstruct public void init() { statelist = enderecobo.loadstatelistselectitem(); } public void changestate(ajaxbehaviorevent event) { string state = (string) ((uiinput) event.getcomponent()).getvalue(); citylist = addressbo.loadcitylist(state); } // ... }

java jsf jsf-2 ejb valuechangelistener

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -