Sunday 15 June 2014

jsf - f:ajax not working when dropdown return null -



jsf - f:ajax not working when dropdown return null -

the dropdown linked converter. ajax works when dropdown value changed. but in case of selection of "-- select --" item dropdown, ajax not invoke listener. not find solution. code given below.

<h:selectonemenu value="#{cc.attrs.beanproperty}" converter="myconverter" > <f:selectitem itemvalue="#{null}" itemlabel="-- select --" /> <f:selectitems value="#{cc.attrs.list}" var="item" itemvalue="#{item}" itemlabel="#{item.name}" /> <f:ajax render=":form1" listener="#{mybean.listener}"/> </h:selectonemenu>

converter:

@facesconverter(value = "myconverter") public class vendorconverter implements converter { @inject objectdao dao; @override public object getasobject(facescontext context, uicomponent component, string value) { if(value == null || value.contains("select")){ homecoming null; } homecoming dao.find(integer.valueof(value)); } @override public string getasstring(facescontext context, uicomponent component, object value) { if(value == null) { homecoming null; } homecoming ((myobject) value).getid().tostring(); } }

could point solution?

since f:ajax not beingness triggered itemvalue="#{null}" or noselectionoption="true" (which improve anyway null usage) recommend following, prevent user go -- select -- value after selected

(unless want user go -- select -- alternative after picked other option)

1) replace

<f:selectitem itemvalue="#{null}" itemlabel="-- select --" />

with

<f:selectitem noselectionoption="true" itemlabel="-- select --" />

2) add together utilize of itemdisabled

<f:selectitem itemdisabled="#{not empty cc.attrs.beanproperty}" noselectionoption="true" itemlabel="-- select --" />

or instead of itemdisabled="#{not empty cc.attrs.beanproperty}" utilize <h:selectonemenu hidenoselectionoption="true"> depend on preferences.

also, note in order find out whats wrong code can seek using placing <h:message or <h:messages in page

ajax jsf jsf-2.2 selectonemenu

No comments:

Post a Comment